0
点赞
收藏
分享

微信扫一扫

Nginx配置auth_basic认证,让用户访问指定页面时输入用户名密码认证

老罗话编程 2024-11-04 阅读 20
nginx运维

配置方法:

[root@localhost ~]# yum -y install httpd-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-99.el7.centos.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                Arch              Version                             Repository          Size
=======================================================================================================
Installing:
 httpd-tools            x86_64            2.4.6-99.el7.centos.1               updates             94 k

Transaction Summary
=======================================================================================================
Install  1 Package

Total download size: 94 k
Installed size: 168 k
Downloading packages:
httpd-tools-2.4.6-99.el7.centos.1.x86_64.rpm                                    |  94 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-tools-2.4.6-99.el7.centos.1.x86_64                                            1/1 
  Verifying  : httpd-tools-2.4.6-99.el7.centos.1.x86_64                                            1/1 

Installed:
  httpd-tools.x86_64 0:2.4.6-99.el7.centos.1                                                           

Complete!


[root@localhost ~]# htpasswd -cb /software/nginx/conf/.htpasswd zhangsan 123456
Adding password for user zhangsan
[root@localhost ~]# htpasswd -b /software/nginx/conf/.htpasswd lisi 123456
Adding password for user lisi


[root@localhost ~]# cd /software/nginx/conf/
[root@localhost conf]# cat .htpasswd
zhangsan:$apr1$2jyBXM8A$Gy2j0U6PbUehvRK1t9F6k1
lisi:$apr1$.D9ff3fE$/rmAzB3aV8VTOXCbDjaht.


[root@localhost conf]# cdweb
[root@localhost conf.d]# vi uhn.conf 

server {
   listen 80;
   server_name www.uhn.cn;

   location / {
   root /data/nginx/html/uhn;
   auth_basic "login password";
   auth_basic_user_file /software/nginx/conf/.htpasswd;
   }

}

访问测试

Nginx配置auth_basic认证,让用户访问指定页面时输入用户名密码认证_nginx



举报

相关推荐

0 条评论