Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Clear advice/configuration for nginx

edited May 2017 in Vanilla 2.0 - 2.8

In the official vanilla documentation it states the ?p= is no longer needed. However when looking through the search results for nginx configuration, every thread including posts by vanilla developers and forum moderators still includes a ?p= check.

Is there an official or working configuration for nginx without using the, according to the documentation depreciated, ?p= routing?

See, https://open.vanillaforums.com/discussion/comment/244840/#Comment_244840 https://open.vanillaforums.com/discussion/comment/242050/#Comment_242050 for previous advice which all use ?p=

Comments

  • That's still using the same ?p= behind the scenes, perhaps I'm mis-understanding that is not actually depreciated?
    It even states, "In Vanilla 2.3, these rules change because the p parameter has been removed in favor of strict usage of PATH_INFO, and therefore no rewrite is needed. However, it’s important that your fastcgi params are setup to pass this information to PHP." but there's no documentation or samples of that.

  • LincLinc Admin

    @Gillingham said:
    It even states, "In Vanilla 2.3, these rules change because the p parameter has been removed in favor of strict usage of PATH_INFO, and therefore no rewrite is needed. However, it’s important that your fastcgi params are setup to pass this information to PHP." but there's no documentation or samples of that.

    Because that's how nginx runs out of the box, as far as I can tell. There's nothing you need to do. It's pointing that out in case you removed it, in which case one would hope you know how to put it back.

    This is what's in my localhost's fastcgi_params:

    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    

    Nothing fancy, just the basic pass-thrus.

    I'm reluctant to start pasting exact files into our docs lest someone just start blindly copy/pasting things and then yell at me when they break their server. :anguished:

  • I guess I can't get that to work out of the box, copying from https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/ with no other redirects I have

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
    
        # Mitigate https://httpoxy.org/ vulnerabilities
        fastcgi_param HTTP_PROXY "";
    
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #include fastcgi_params;
        include snippets/fastcgi-php.conf;
    }
    

    Results in a 404 for any of the non-index URLs, including fastcgi_params instead of the snippet results in 200 response with no body from the index, and still 404s for non-index. The fastcgi_params and snippets are both unmodified from the ubuntu nginx packaging.

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            if (-f $request_filename) {
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            }
        }
    
        location @site {
           rewrite ^ /index.php?p=$uri&$args last;
        }
    
        location / {
           try_files $uri @site;
        }
    

    Works, but I'm trying to stay current with the recommended configuration to prevent issues down the line.

  • LincLinc Admin

    It appears my localhost is still using the old 'p' parameter as well, so I'll ask to see what we're doing internally rather than conjecturing.

  • Just popping by to confirm that the following is working in nginx config on 2.3.1:

    location / {
        try_files $uri $uri/ /index.php?p=$uri&$args;
    }
    

    Which means the docs are a bit misleading, as I spent a good couple of nights tearing my hair out :anguished:

Sign In or Register to comment.