vi /usr/local/httpd/conf/extra/httpd-vhosts.conf//创建独立的配置文件
<VirtualHost *:80>DocumentRoot "/var/www/html/kgccom"ServerName www.kgc.comErrorLog "logs/www.kgc.com.error_log"CustomLog "logs/www.kgc.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost><VirtualHost *:80>DocumentRoot "/var/www/html/kccecom"ServerName www.kcce.comErrorLog "logs/www.kcce.com.error_log"CustomLog "logs/www.kcce.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost>//加载独立的配置文件
vi /usr/local/httpd/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf# 重启服务
systemctl restart httpd
3、基于 IP 地址、基于端口的虚拟主机
基于 IP 地址的虚拟主机
vi /usr/local/httpd/conf/extra/httpd-vhosts.conf//创建独立的配置文件
<VirtualHost 192.168.72.154:80>DocumentRoot "/var/www/html/kgccom"ServerName www.kgc.comErrorLog "logs/www.kgc.com.error_log"CustomLog "logs/www.kgc.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost><VirtualHost 192.168.72.154:80>DocumentRoot "/var/www/html/kccecom"ServerName www.kcce.comErrorLog "logs/www.kcce.com.error_log"CustomLog "logs/www.kcce.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost>
基于端口的虚拟主机
vi /usr/local/httpd/conf/extra/httpd-vhosts.conf//创建独立的配置文件
<VirtualHost 192.168.72.154:81>DocumentRoot "/var/www/html/kgccom"ServerName www.kgc.comErrorLog "logs/www.kgc.com.error_log"CustomLog "logs/www.kgc.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost><VirtualHost 192.168.72.154:82>DocumentRoot "/var/www/html/kccecom"ServerName www.kcce.comErrorLog "logs/www.kcce.com.error_log"CustomLog "logs/www.kcce.com.access_log" common
<Directory "/var/www/html">Require all granted
</Directory></VirtualHost># 还需要再主配置文件添加 Listen 进行监听端口