我正在尝试设置我的服务器,以便在浏览域中的任何文件之前需要进行身份validation。 但是,我想显示一个自定义的错误页面( placeholder.html ),当有人无法进行身份validation。
我尝试了下面列出的服务器configuration,但它将我的浏览器发送到无限redirect循环(甚至没有提供authentication窗口)。 任何人都可以解释吗? 你将如何解决这个问题?
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; } }
您必须在location和error_page指令中的placeholder.html之前添加前导斜杠。