
我正在嘗試設定我的伺服器,以便在瀏覽網域上的任何檔案之前需要進行身份驗證。但是,我想placeholder.html
在有人無法進行身份驗證時顯示自訂錯誤頁面 ( )。
我嘗試了下面列出的伺服器配置,但它會將我的瀏覽器發送到無限重定向循環(甚至不顯示身份驗證視窗)。誰能解釋一下嗎?你會如何解決這個問題?
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.html index.htm;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/auth/example.com.auth;
error_page 401 placeholder.html;
location = placeholder.html {
auth_basic off;
}
location / {
try_files $uri $uri/ =404;
}
}
答案1
您必須placeholder.html
在location
anderror_page
指令之前添加前導斜線。