Nginx PHP页面找不到总是返回404

同目录下 html 没有问题,一访问 *.php 就404

原因:
nginx 配置的 server 段没有指定 root,导致 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name 中的 $document_root并不起作用

解决方法:
server 段加上 root 网站目录,或不使用 $document_root变量,转而使用其它变量或直接指定路径

server {
    #使用 one 这个缓存
        #proxy_cache    one;
        #proxy_cache_valid   any  10m;

        listen         80;
        server_name    abc.com ;

        # 就是增加的下面的 root,指定了当前 server 的root指向哪里
        root           /a/b/c;

        location / {
            root     /home/wwwroot/tyshgm-www;
            index    index.html  index.php;

            try_files  $uri  $uri/  /index.php?$args;
        }

        rewrite /wp-admin$ $scheme://$host$uri/ permanent;

        error_page   401 402 403 404 500 502 503 504  /oops.html;
        location = /oops.html {
            root     /a/b/c;
        }

        location  ~\.php$ {
            root            /a/b/c;
            fastcgi_pass    unix:/run/php-fpm/c.sock;
            #fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }
    }
posted @ 2021-06-10 17:31  试试手气  阅读(818)  评论(0编辑  收藏  举报