NGINX/FastCGI 导致 404 的配置问题
NGINX/FastCGI config issues causing 404s
我目前正在尝试使用 NGINX 配置 Wordpress 多站点。 NGINX 配置测试通过:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
但是当我加载网站时,我只是得到一个 File Not Found.
页面。从我的配置:
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-.*) last;
rewrite ^(/[^/]+)?(/.*.php) 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; } }
}
从我的 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
我的文档根目录是 /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
不太确定从这里到哪里去,所以任何帮助将不胜感激。
很高兴您设法解决了这个问题。正如我的评论中提到的,将以下行添加到您的服务器块解决了这个问题:
SCRIPT_FILENAME $document_root$fastcgi_script_name
我目前正在尝试使用 NGINX 配置 Wordpress 多站点。 NGINX 配置测试通过:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
但是当我加载网站时,我只是得到一个 File Not Found.
页面。从我的配置:
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-.*) last;
rewrite ^(/[^/]+)?(/.*.php) 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; } }
}
从我的 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
我的文档根目录是 /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
不太确定从这里到哪里去,所以任何帮助将不胜感激。
很高兴您设法解决了这个问题。正如我的评论中提到的,将以下行添加到您的服务器块解决了这个问题:
SCRIPT_FILENAME $document_root$fastcgi_script_name