码迷,mamicode.com
首页 > 其他好文 > 详细

nginx 用户认证

时间:2017-11-09 22:32:36      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:nginx 用户认证

作用:web上的一些内容不想被其他人知道,但是又想让部分人看到。nginx的http auth模块以及Apache http auth都是很好的解决方案。

默认情况下nginx已经安装了ngx_http_auth_basic_module模块,如果不需要这个模块,可以加上 --without-http_auth_basic_module 。

配置:

修改nginx.conf  文件

server {

  1. listen       80;

  2. server_name  localhost;

  3. auth_basic "Input Password:";        //认证提示符

  4. auth_basic_user_file "/usr/local/nginx/pass";        //认证密码文件

  5. location / {

  6. root   html;

  7. index  index.html index.htm;

  8. }

  9. }

生成密码文件,创建用户及密码

使用htpasswd命令创建账户文件,需要确保系统中已经安装了httpd-tools。

  1. [root@svr5 ~]# yum -y install  httpd-tools

  2. [root@svr5 ~]# htpasswd -cm /usr/local/nginx/pass   tom        //创建密码文件,注意pass的位置

  3. New password:

  4. Re-type new password:

  5. Adding password for user tom

  6. [root@svr5 ~]# htpasswd -m /usr/local/nginx/pass   jerry    

  7. //追加用户,不使用-c选项

  8. New password:

  9. Re-type new password:

  10. Adding password for user jerry

    重启Nginx服务


nginx 用户认证

标签:nginx 用户认证

原文地址:http://caotian.blog.51cto.com/13441668/1980416

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!