配置方法:
[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;
}
}
访问测试