-
打开Apache的配置文件
httpd.conf
,通常位于/etc/httpd/conf/httpd.conf
或/etc/apache2/httpd.conf
。 -
确保
NameVirtualHost *:80
指令被解注释(移除#
),以启用基于域名的虚拟主机。 -
为每个网站添加
<VirtualHost>
配置块:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/example1" ServerName www.example1.com ServerAlias example1.com ErrorLog "logs/example1.com-error_log" CustomLog "logs/example1.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/example2" ServerName www.example2.com ServerAlias example2.com ErrorLog "logs/example2.com-error_log" CustomLog "logs/example2.com-access_log" common </VirtualHost>
确保为每个网站指定正确的DocumentRoot
(网站文件目录)、ServerName
(主机名)和ServerAlias
(别名)。
4、重启Apache。
标签:httpd,www,端口,example2,conf,example1,Apache,80,com From: https://www.cnblogs.com/thingk/p/18249142