简体   繁体   English

NGINX/FastCGI 配置问题导致 404s

[英]NGINX/FastCGI config issues causing 404s

I'm currently trying to configure a Wordpress Multisite using NGINX.我目前正在尝试使用 NGINX 配置 Wordpress 多站点。 The NGINX config test passes: NGINX 配置测试通过:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

But I simply get a File Not Found.但我只是得到一个File Not Found. page when I load the site.加载网站时的页面。 From my config:从我的配置:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

server {
    listen        80 default_server;
    access_log    /var/log/nginx/access.log main;

    client_header_timeout 60;
    client_body_timeout   60;
    keepalive_timeout     60;
    gzip                  off;
    gzip_comp_level       4;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server_name <my-domain>.com ;

    access_log   /var/log/nginx/gnbwpms.access.log;
    error_log    /var/log/nginx/gnbwpms.error.log debug;

    index index.php;

    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;  
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;                     
        rewrite ^(/[^/]+)?(/.*.php) $2 last;                   
    }

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

    location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
    fastcgi_index index.php;
    }

    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
            access_log off; log_not_found off; expires max;
    }

    location = /robots.txt { access_log off; log_not_found off; }
    location ~ /\. { deny  all; access_log off; log_not_found off; }    }
}

And from my nginx error.log :从我的 nginx error.log

2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 01
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 07
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 01
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 16
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 02
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record length: 22
2022/01/04 14:44:43 [error] 8368#8368: *552 FastCGI sent in stderr: "Primary script 
   unknown" while reading response header from upstream, client: <client IP>, 
server: <my-domain>.com, request: "GET / HTTP/1.1", upstream: " 
   fastcgi://unix:/var/run/php-fpm/www.sock:", host: "<server IP>"
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 01
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 06
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 01
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 51
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 07
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record byte: 00
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi record length: 81
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi parser: 0
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi header: "Status: 404 Not Found"
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi parser: 0
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi header: "Content-type: text/html; charset=UTF-8"
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi parser: 1
2022/01/04 14:44:43 [debug] 8368#8368: *552 http fastcgi header done
2022/01/04 14:44:43 [debug] 8368#8368: *552 HTTP/1.1 404 Not Found

My docroot is /var/www/html and the logs seem to show requests are being sent to the right place:我的 docroot 是/var/www/html并且日志似乎显示请求正在发送到正确的位置:

2022/01/04 14:44:43 [debug] 8368#8368: *552 trying to use file: "/index.php" 
"/var/www/html/index.php"
2022/01/04 14:44:43 [debug] 8368#8368: *552 try file uri: "/index.php"
2022/01/04 14:44:43 [debug] 8368#8368: *552 generic phase: 14

Not really sure where to go from here, so any help would be greatly appreciated.不太确定 go 从这里到哪里,所以任何帮助将不胜感激。

Glad you managed to sort this.很高兴你设法解决了这个问题。 As mentioned in my comment, adding the following line to your server block resolved the issue:正如我的评论中提到的,将以下行添加到您的服务器块解决了这个问题:

SCRIPT_FILENAME $document_root$fastcgi_script_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM