rryqszq4 / ngx-php

ngx-php - Embedded php7 or php8 scripting language for nginx module. Mainline development version of the ngx-php.
BSD 2-Clause "Simplified" License
642 stars 55 forks source link

Concrete example from standard nginx.conf? #147

Open roukmoute opened 1 year ago

roukmoute commented 1 year ago

Is it possible to convert an example from standard nginx.conf like this?

server {
    server_name domain.tld www.domain.tld;
    root /var/www/project/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}
joanhey commented 1 year ago

Looks like you are using a Front Controller (index.php).

Here are some examples: https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/PHP/php-ngx/deploy

There a lot of ways to do it.

I'll create an example for a Front Controller (when I have free time)

roukmoute commented 1 year ago

It is a Front Controller that is used to take any "route" and redirect it to index.php, and currently I don't know how to do it.

For example, how concatenate index.php with its optionnal GET arguments?

I know the repository you sent me, but this is perfect example of non applicable because all routes is hard coded.

rryqszq4 commented 1 year ago

@roukmoute It's route anything.

server {
    listen 80;
    server_name localhost;
    access_log logs/cp-stats-web.access.log ;
    root /home/mbxps/mbxps/develop/quanzhao/production/cp-stats-web/public;
    index index.php index.html index.htm;

    location = /favicon.ico {

    }

    location ~ ^/(echarts|antv|jquery|jqueryui|d3|nvd3|semantic|bootstrap|static)/ {
        }

    location ~ /clf {
        proxy_pass http://10.16.172.70:8888;
    }

    location ~ ^(.*)$ {
        content_by_php '
                global $START_TIME;
                $START_TIME = microtime(true);

                if (!defined("APPLICATION_PATH")){
                        define("APPLICATION_PATH", "/home/mbxps/mbxps/develop/quanzhao/production/cp-stats-web");
                }

                require_once(APPLICATION_PATH."/vendor/autoload.php");

                require_once(APPLICATION_PATH."/framework/Dispatch.php");

                $application = new Dispatch();
                $application->run();
        ';
    }
}
joanhey commented 1 year ago

Also I'm finishing and adapter for Ngx-php to use any php app, without touch 1 line of code.

I made it first for Workerman https://github.com/joanhey/AdapterMan

joanhey commented 1 year ago

@rryqszq4 My email, I want to contact you. joanhey@kumbiaphp.com

rryqszq4 commented 1 year ago

@rryqszq4 My email, I want to contact you. joanhey@kumbiaphp.com

@joanhey My email is rryqszq@gmail.com