0
我正在嘗試提供維護頁面。所以我給了try_files
一試,總是爲maintenance.html
服務。如果url具有.html擴展名,則Nginx不重定向
如果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;
}
我甚至試過這種if-based solution,但似乎沒有任何工作。我錯過了什麼?
503不重定向。應該使用3XX。 – diarpi
謝謝@diarpi的更正。 –
我以爲'= 404'只是爲了防止'maintenance.html'不存在。但是對於重定向,它更準確。無論如何,這並沒有改變這樣一個事實,即輸入'app.amazing.com/test.html'仍然會返回404。 – Buzut