[转载]nginx 里使用 http auth basic 认证和 ssl
转载地址:http://www.tetx.com/program/htm/tetx/blog/view/blog_id/1209961063/index.htm
nginx 安装在 /usr/local/nginx/ 目录下
1、nginx 使用 http auth basic 认证
代码可以放在 http, server, location, limit_except 段
#准备:
cd /usr/local/nginx/conf
mkdir auth
cd auth/
htpasswd -c -d .htpasswd 用户名 #回车并输入密码再回车,-c 是创建新的文件,如果已经存在就不要使用 -c 了,-d 是密码的加密方式(Use crypt() encryption for passwords.)
#编辑host配置,在 server 段加:
auth_basic “Restricted”;
auth_basic_user_file auth/.htpasswd; #可以使用相对路径,相对于 nginx.conf 位置
#检查语法:
sudo /usr/local/nginx/sbin/nginx -t
#重新启用配置:
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
注意:Since version 0.6.7 [...]