【发布时间】:2015-08-05 13:12:28
【问题描述】:
我正在尝试在 Nginx 上进行基本身份验证。我已经在 Ubuntu 14.04 上启动并运行了 1.9.3 版本,它适用于一个简单的 html 文件。
这是html文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
"Some shoddy text"
</body>
</html>
这是我的 nginx.conf 文件:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name 192.168.1.30;
location / {
root /www;
index index.html;
auth_basic "Restricted";
auth_basic_user_file /etc/users;
}
}
}
我使用 htpasswd 在 /etc 下的“users”文件中创建了两个用户(用户名“calvin”密码“Calvin”,用户名“hobbes”密码“Hobbes”)。它的加密方式如下所示:
calvin:$apr1$Q8LGMfGw$RbO.cG4R1riIfERU/175q0
hobbes:$apr1$M9KoUUhh$ayGd8bqqlN989ghWdTP4r/
所有文件都属于 root:root。服务器 IP 地址是 192.168.1.30,我直接在 conf 文件中引用它。
如果我注释掉两个 auth 行并重新启动 nginx,一切正常,但是如果我取消注释它们,那么当我尝试加载站点时确实会收到用户名和密码提示,但随后会立即收到错误 500内部服务器错误似乎持续存在,我必须重新启动 nginx。
任何人都可以看到我在这里做错了什么?我在标准的 Ubuntu 14.04 apt-get 版本的 Nginx (1.4.something) 上有相同的行为,所以我不认为它是 nginx 版本。
【问题讨论】:
标签: nginx