我的Nginx服务器没有显示我的404页面。相反,每当尝试访问不存在的页面或目录时,它只是在我的web文件夹的根目录中提供我的索引(.php)(没有相应的样式表)。
这是我在/ 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;
}
}
这无疑取决于我对此的陌生并且过多地摆弄它,所以这里也可能存在其他问题(就此而言,提示如何 - 一旦其余部分得到修复 - 我可以强制HTTPS连接会膨胀!)。感谢帮助和建设性的意见,谢谢!
答案 0 :(得分:4)
如果文件不存在,你将重写为index.php,所以它永远不会进入你的try_files或errorpage ......
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
^应该被删除,除非你有特定的目的