nginx下使用HTTP basic auth保护网站目录

nginx 的 http auth basic 保护网站目录配置

 1 server {
 2     server_name blog.slogra.com;
 3     root /var/www/blog.slogra.com;
 4     include /etc/nginx/fastcgi_php;
 5     location / {
 6         auth_basic            "Password please";
 7         auth_basic_user_file  /usr/local/nginx/conf/htpasswd;
 8         index index.php;
 9     }
10 }

在nginx的server中加入了

auth_basic "Password please";
auth_basic_user_file /usr/local/nginx/conf/htpasswd;

然后重启nginx即可


 

最后我们说下怎么在nginx下生成htpasswd

下载这个python文件:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py

然后运行下面的代码生成验证访问验证文件

chmod 777 htpasswd.py
./htpasswd.py -c -b htpasswd username password
#-c为生成文件 htpasswd为文件名

 

posted @ 2015-10-16 09:44  木以成舟  阅读(220)  评论(0编辑  收藏  举报