虚拟主机—基于 IP
一、添加虚拟主机ip地址 192.168.9.130 和 192.168.9.131 并启用
nmcli connection modify ens160 +ipv4.addresses 192.168.9.130/24
nmcli connection up ens160
nmcli connection modify ens160 +ipv4.addresses 192.168.9.131/24
nmcli connection up ens160
检查是否添加成功:
ip ad
展示结果:
二、编写主机配置文件host.conf (注意文件放置的路径)
该配置文件所在路径为:/etc/httpd/conf.d/host.conf
输入命令:
vim /etc/httpd/conf.d/host.conf
开始编写(documentroot 后面填的路径是你www目录下130或131目录所在路径):
<directory /var/www>
allowoverride none
require all granted
</directory>
<virtualhost 192.168.9.130:80>
servername 192.168.9.130
documentroot /var/www/130
ErrorLog "logs/error_130_log"
CustomLog "logs/custom_130_log" combined
</virtualhost>
<virtualhost 192.168.9.131:80>
servername 192.168.9.131
documentroot /var/www/131
ErrorLog "logs/error_131_log"
CustomLog "logs/custom_131_log" combined
</virtualhost>
三、前往/var/www路径下创建130 和 131目录
cd /var/www
mkdir 130 -p
echo welocome to 130 > 130/index.html
mkdir 131 -p
echo welocome to 131 > 131/index.html
四、重启httpd并关闭防火墙
systemctl restart httpd
systemctl stop firewalld
五、修改权限
setenforce 0
六、检查是否成功
日志的目录在 /var/log/httpd/
cd /var/log/httpd/
ll
|