安装apache的htpasswd工具
使用htpasswd工具生成密码文件
1
| htpasswd -bc .htpasswd user userpasswd
|
nginx配置
1 2 3 4 5 6
| location /xxx { root /usr/local/example; index index.html index.htm; auth_basic ""; uth_basic_user_file /etc/nginx/.htpasswd; }
|
注意
上面配置可能造成php无法解析,此时需要在location里面再配置一层location:
1 2 3 4 5 6 7 8 9 10
| location /xxx { root /usr/local/example; index index.html index.htm; auth_basic ""; uth_basic_user_file /etc/nginx/.htpasswd;
location ~ .*\.(php|php5)?$ { } }
|