【发布时间】:2016-01-11 11:47:16
【问题描述】:
我正在尝试使用密码保护我的 Nginx 配置中的默认服务器。但是,当我访问该站点时,没有显示用户名/密码对话框。 Nginx 照常返回内容。这是完整的配置:
worker_processes 1;
events
{
multi_accept on;
}
http
{
include mime.types;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
tcp_nodelay on;
gzip on;
# Set path for Maxmind GeoLite database
geoip_country /usr/share/GeoIP/GeoIP.dat;
# Get the header set by the load balancer
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
real_ip_recursive on;
server {
listen 80;
server_name sub.domain.com;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/sub.domain.com.htpasswd;
expires -1;
access_log /var/log/nginx/sub.domain.com.access default;
error_log /var/log/nginx/sub.domain.com.error debug;
location / {
return 200 '{hello}';
}
}
}
有趣的是,当我尝试使用无效的文件路径作为 auth_basic_user_file 的值时,configtest 仍然通过。不应该是这样的。
这是 Nginx 和系统信息:
[root@ip nginx]# nginx -v
nginx version: nginx/1.8.0
[root@ip nginx]# uname -a
Linux 4.1.7-15.23.amzn1.x86_64 #1 SMP Mon Sep 14 23:20:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
我们正在使用通过 yum 获得的 Nginx RPM。
【问题讨论】:
标签: authentication nginx configuration