[英]Nginx not displaying 404 page, instead serving index file in root
My Nginx server is not displaying my 404 page. 我的Nginx服务器没有显示我的404页面。 Instead, whenever trying to access a non-existent page or directory, it merely serves my index(.php) in the root of my web folder (without the corresponding stylesheet). 相反,每当尝试访问不存在的页面或目录时,它只是在我的web文件夹的根目录中提供我的索引(.php)(没有相应的样式表)。
Here's my own 'default' file under /etc/nginx/sites-available: 这是我在/ etc / nginx / sites-available下的'默认'文件:
server {
listen 80;
listen [::]:80 ipv6only=on;
listen 443 ssl;
listen [::]:443 ipv6only=on ssl;
add_header Strict-Transport-Security max-age=15768000;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
ssl_prefer_server_ciphers on;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
index index.php;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
try_files $uri $uri/ =404;
error_page 403 404 405 /error/404.html;
error_page 500 501 502 503 504 /error/50x.html;
location ^~ /error/ {
internal;
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
This is undoubtedly down to me being new to this and fiddling with it too much, so there are likely other problems here too (on that note, a tip as to how - once the rest is fixed - I can force HTTPS connections would be swell!). 毫无疑问,这对我来说是新手并且过多地摆弄它,所以这里也可能存在其他问题(关于如何 - 关于如何 - 一旦其余部分得到修复 - 我可以强制HTTPS连接会膨胀!)。 Help and constructive input appreciated, thanks! 感谢帮助和建设性的意见,谢谢!
you are rewriting to index.php if the file doesn't exist, so it never makes it to your try_files or errorpage... 如果文件不存在,你将重写为index.php,所以它永远不会进入你的try_files或errorpage ......
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
^ should be removed, unless you have a specific purpose for it ^应该被删除,除非你有特定的目的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.