nginx + php-fpm = File not found

前端 未结 8 1687
孤街浪徒
孤街浪徒 2021-02-07 01:25

When i try accessing info.php I get a File not found. error.

I tried some Tutorials to no avail.

Configs: default:

ser         


        
相关标签:
8条回答
  • 2021-02-07 02:11

    In location nginx section, if you use root then the value for $document_root$fastcgi_script_name is correct. But if you use alias the value is wrong. When use alias you need use $request_filename instead of $document_root$fastcgi_script_name.

    location /myapp {
        alias /home/site/www/myapp;
        location ~* "\.php$" {
            fastcgi_pass   php_fpm_server:9000;
            fastcgi_index  index.php;
    
            # Works in all cases.
            fastcgi_param  SCRIPT_FILENAME $request_filename;
    
            ## Not work for 'alias' directive, only for 'root' directive.
            # fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    

    Documentation for variables above:

    $request_filename

    file path for the current request, based on the root or alias directives, and the request URI

    $document_root

    root or alias directive’s value for the current request

    $fastcgi_script_name

    request URI or, if a URI ends with a slash, request URI with an index file name configured by the fastcgi_index directive appended to it. This variable can be used to set the SCRIPT_FILENAME and PATH_TRANSLATED parameters that determine the script name in PHP. For example, for the “/info/” request with the following directives

    Read more

    • https://serverfault.com/questions/465607/nginx-document-rootfastcgi-script-name-vs-request-filename
    0 讨论(0)
  • 2021-02-07 02:12

    Nginx & Symlinks

    Note, if root /var/www; is a symlink, change it to root /var/www/; otherwise nginx won't go past the symlink and you'll get a File not found error

    0 讨论(0)
提交回复
热议问题