Nginx 401 Unauthorized 的定位与修复
请求返回 401 Unauthorized,响应头可能带 WWW-Authenticate。常见于 Basic Auth、Bearer Token、上游认证或客户端证书。
curl -v http://<host>/protected
nginx -T | grep -nE 'auth_basic|auth_basic_user_file|proxy_set_header Authorization'
tail -f /var/log/nginx/error.log
ls -l /etc/nginx/.htpasswd
.htpasswd 文件路径/权限错误,或密码未生成。Server 和 WWW-Authenticate,判断 401 来自 Nginx 还是上游。htpasswd 重新生成密码文件,确认路径和权限。proxy_set_header Authorization $http_authorization 透传。ssl_verify_client。nginx — 配置与日志curl — 带凭据复现htpasswd — Basic Auth 文件