![nginx 500 错误而不是 404](https://linux22.com/image/587574/nginx%20500%20%E9%94%99%E8%AF%AF%E8%80%8C%E4%B8%8D%E6%98%AF%20404.png)
我有以下 nginx 配置(在/etc/nginx/sites-available/default
)
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
我在无效 URL 上收到 500 服务器错误,而不是 404 错误。我该如何纠正这个问题?
答案1
这很可能是由于块的工作方式造成的location /
。请按如下方式进行更改...
location / {
try_files $uri $uri/ =404;
}