Linux下配置基于用户认证的虚拟主机
一、首先进入到/etc/httpd/conf.d 目录下
[root@localhost ~]# cd /etc/httpd/conf.d
二、向系统中添加所要创建的虚拟主机的IP
[root@localhost conf.d]# nmcli connection modify ens160 +ipv4.addresses 192.168.48.130/24
三、启用一下网络连接
[root@localhost conf.d]# nmcli connection up ens160
四、创建账户和并设置密码
[root@kittod conf.d]# htpasswd -c /etc/httpd/mima abc
New password:
Re-type new password:
Adding password for user abc
[root@kittod conf.d]# htpasswd /etc/httpd/mima tom
New password:
Re-type new password:
Adding password for user tom
五、创建文件夹,并写入内容
[root@kittod conf.d]# mkdir /usr/local/mysecret/
[root@kittod conf.d]# echo This is mysecret > /usr/local/mysecret/index.html
六、在/etc/httpd/conf.d文件夹下用vim打开host.conf配置文件
(1)在里面再创建一个“directory”目录标签,写入以下内容:
<directory /usr/local/mysecret>
authtype basic
authname "This is a private directory,Please Login: "
authuserfile /etc/httpd/mima
require user abc tom
</directory>
(2)在虚拟主机的配置中加入
alias /mysecret /var/mysecret
alias此处起目录间相互联系的作用
(3)保存并退出,然后重启httpd服务,关闭防火墙
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# systemctl stop firewalld
七、修改linux /etc/hosts配置文件
在第三行加入内容
八、在windows下的hosts配置文件中也加入该内容
路径:C:\Windows\System32\drivers\etc
注:
报错时可输入改语句,打开权限
setenforce 0