Redirect Nginx没有';如果url具有.html扩展名,则不能重定向
我在试着提供一个维护页面。因此,我给了Redirect Nginx没有';如果url具有.html扩展名,则不能重定向,redirect,nginx,Redirect,Nginx,我在试着提供一个维护页面。因此,我给了try\u文件一次尝试,并始终提供maintenance.html 如果url类似于app.amazing.com或类似于app.amazing.com/[a-z0-9]*,它会工作得很好,但一旦有html扩展名,Nginx就会尝试提供这个文件(例如:app.amazing.com/test.html),如果不存在,则返回404 server { listen [::]:443; listen 443; server_name ap
try\u文件
一次尝试,并始终提供maintenance.html
如果url类似于app.amazing.com或类似于app.amazing.com/[a-z0-9]*
,它会工作得很好,但一旦有html扩展名,Nginx就会尝试提供这个文件(例如:app.amazing.com/test.html
),如果不存在,则返回404
server {
listen [::]:443;
listen 443;
server_name app.amazing.com;
root /var/www/front/public;
include /etc/nginx/conf.d/expires.conf;
charset utf-8;
location / {
try_files /maintenance.html =404;
}
}
我也尝试过这样的重写:
location / {
rewrite (.*) /maintenance.html break;
}
我甚至试过这个,但似乎没有任何效果。我错过了什么吗?更新:测试和工作
server {
listen [::]:443;
listen 443;
server_name app.amazing.com;
root /var/www/front/public;
include /etc/nginx/conf.d/expires.conf;
charset utf-8;
set $maintenance on;
if ($uri ~* \.(ico|css|js|gif|jpe?g|png|html)(\?[0-9]+)? ) {
set $maintenance off;
}
if ($maintenance = on) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
location / {
# here hoes your usual location / rules
try_files $uri $uri/ =404;
}
}
请将404代码更改为503,如下所示:
server {
listen [::]:443;
listen 443;
server_name app.amazing.com;
root /var/www/front/public;
include /etc/nginx/conf.d/expires.conf;
charset utf-8;
location / {
try_files $uri $uri/ =404;
}
}
404=未找到
更新:
302=临时重定向503不是重定向。应该使用3XX。我认为
=404
只是为了防止维护.html
不存在。但对于重定向,它更准确。无论如何,这并没有改变这样一个事实,即键入app.amazing.com/test.html仍然返回404。