nginx 500 错误而不是 404

nginx 500 错误而不是 404

我有以下 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;
}

相关内容