Want more timely Centmin Mod News Updates?
Become a Member

PHP-FPM Connecting nginx to PHP FPM

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by dorobo, Jul 13, 2014.

  1. dorobo

    dorobo Active Member

    420
    104
    43
    Jun 6, 2014
    Ratings:
    +162
    Local Time:
    4:10 PM
    latest
    latest
    this code from /usr/local/nginx/conf/php.conf

    Code:
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;
    is outdated according to http://wiki.nginx.org/PHPFcgiExample

    it should be

    Code:
    location ~ [^/]\.php(/|$) {
                    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                    if (!-f $document_root$fastcgi_script_name) {
                            return 404;
                    }
     
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    remember ifisevil (http://wiki.nginx.org/IfIsEvil)? it says that in this case, using if "is more appropriate" and "one of the 100% safe thing to use if with."

    see also the testing part. When I use /test.php/foo/bar.php?v=1 in the centminmod default php.conf it results in a 404 not found instead of something like this

    Code:
    array (
      'USER' => 'www-data',
      'HOME' => '/var/www',
      'FCGI_ROLE' => 'RESPONDER',
      'QUERY_STRING' => 'v=1',
      'REQUEST_METHOD' => 'GET',
      'CONTENT_TYPE' => '',
      'CONTENT_LENGTH' => '',
      'SCRIPT_FILENAME' => '/var/www/test.php',
      'SCRIPT_NAME' => '/test.php',
      'PATH_INFO' => '/foo/bar.php',
      'REQUEST_URI' => '/test.php/foo/bar.php?v=1',
      'DOCUMENT_URI' => '/test.php/foo/bar.php',
      'DOCUMENT_ROOT' => '/var/www',
      'SERVER_PROTOCOL' => 'HTTP/1.1',
      'GATEWAY_INTERFACE' => 'CGI/1.1',
      'SERVER_SOFTWARE' => 'nginx/1.4.0',
      'REMOTE_ADDR' => '192.168.56.1',
      'REMOTE_PORT' => '44644',
      'SERVER_ADDR' => '192.168.56.3',
      'SERVER_PORT' => '80',
      'SERVER_NAME' => '',
      'HTTPS' => '',
      'REDIRECT_STATUS' => '200',
      'HTTP_HOST' => 'lemp.test',
      'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0',
      'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
      'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
      'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
      'HTTP_CONNECTION' => 'keep-alive',
      'PHP_SELF' => '/test.php/foo/bar.php',
      'REQUEST_TIME' => 1367829847,
    )

     
    Last edited: Jul 13, 2014
    • Like Like x 1
  2. eva2000

    eva2000 Administrator Staff Member

    30,950
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,415
    Local Time:
    6:10 PM
    Nginx 1.13.x
    MariaDB 5.5
    interesting info.. will have to chew on it and digest it first

    but not sure how updated that info is as alot of wiki pages are older now ? maybe @Floren would know :)

    edit: thought part of the reason for original way was to prevent test.php/foo/bar.php requests as well ?

    i.e. not to serve

    Code:
     'REQUEST_URI' => '/test.php/foo/bar.php?v=1',
    how many php web apps route php like such though ?

    ownCloud sort of does https://community.centminmod.com/resources/how-to-install-owncloud-on-centmin-mod-nginx.1/ and uses such a similar configuration though

    Code:
    location ~ ^(.+?\.php)(/.*)?$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $1 = 404;
    maybe best to leave it as is and let folks with php web apps that route their php as such have a custom config of their own ?

    thanks :)
     
  3. eva2000

    eva2000 Administrator Staff Member

    30,950
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,415
    Local Time:
    6:10 PM
    Nginx 1.13.x
    MariaDB 5.5