侧边栏壁纸
  • 累计撰写 223 篇文章
  • 累计创建 205 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

LNMP--nginx用户认证

zhanjie.me
2018-02-01 / 0 评论 / 0 点赞 / 0 阅读 / 0 字

LNMP--nginx用户认证

  在LNMP架构下也能做用户认证。首先需要安装apache,可以使用 yum install httpd 安装。然后生成密码文件。

[root@localhost ~]# htpasswd -c -m /usr/local/nginx/conf/htpasswd test

New password:

Re-type new password:

Adding password for user test

  这样就添加了 test 用户,第一次添加时需要加 -c 参数,第二次添加时不需要 -c 参数。在nginx的虚拟主机配置文件中添加:

location /uc_server/ {

        auth_basic  "Auth";

        auth_basic_user_file  /usr/local/nginx/conf/htpasswd;

    }

  这样就把请求 /uc_server/ 的访问给限制了,只有输入用户名和密码才可以继续访问,基本上和apache的配置类似。

  检查和重新加载配置

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

  浏览器访问:

bf81947f9a3a71970c687a87ea1369b017-1dc1ca40-qhyzmtdy.png

0

评论区