出现问题
[root@localhost ~]# curl -uuser:123 -x127.0.0.1:80 test.com
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.0</center>
</body>
</html>
查auth_basic_user_file
[root@localhost ~]# vi /usr/local/nginx/conf/vhost/test.com.conf
1 server
2 {
3 listen 80;
4 server_name test.com;
5 index index.html index.htm index.php;
6 root /data/wwwroot/test.com;
7
8 location /
9 {
10 auth_basic "Auth";
11 auth_basic_user_file /usr/local/nginx/conf/htpasswd;
12 }
13 }
auth_basic_user_file指定的目录/usr/local/nginx/conf/htpasswd
查命令历史
[root@localhost ~]# htpasswd -c -m /data/.htpasswd user
New password:
Re-type new password:
Adding password for user user
解决方案
[root@localhost ~]# rm -f /data/.htpasswd
[root@localhost ~]# htpasswd -c /usr/local/nginx/conf/htpasswd user
New password:
Re-type new password:
Adding password for user user
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# curl -uuser:123 -x127.0.0.1:80 test.com
test.com