Nginx 用户认证

访问一些比较私密的页面 ( 如管理后台,数据后台 ) 时,咱们就能够设置访问该页面时须要使用用户名和密码进行验证,这就是用户认证php

[root@localhost ~]$ cat /usr/local/nginx/conf/vhost/test.com.conf server { listen 80; server_name www.test.com; index index.html index.html index.php; root /data/www; location /admin/ { auth_basic "Auth";                            # 指定认证说明信息
        auth_basic_user_file  /usr/local/nginx/conf/htpasswd;    # 指定用户认证文件
 } }
[root@localhost ~]$ yum install -y httpd-tools                          # 须要使用到 Apache 的 htpasswd 工具来建立认证用户
[root@localhost ~]$ htpasswd -c /usr/local/nginx/conf/htpasswd user1    # 建立第一个认证用户要用 -c Create a new file 参数
[root@localhost ~]$ htpasswd /usr/local/nginx/conf/htpasswd user2       # 建立第二个认证用户不须要再加 -c 参数
[root@localhost ~]$ /usr/local/nginx/sbin/nginx -t [root@localhost ~]$ /usr/local/nginx/sbin/nginx -s reload

相关文章
相关标签/搜索