1
我想删除php文件扩展名。所以我搜索并尝试了这个代码。重写文件扩展名后Nginx服务器不重定向
它运作良好,但当我尝试不存在的页面。
它只是说“文件未找到”。在我写'try_files $ uri ...;'之前它返回/404.html。
我试过try_files $ uri = 404;在.php $中,但所有页面都返回到/404.html。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
include /etc/nginx/default.d/*.conf;
location/{
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
error_page 404 /404.html;
location = /40x.html {
root /var/www/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
我该如何解决这个问题?