首先找到Apache的配置文件httpd.confphp
find / -name httpd.conf
找到如下代码处html
#Virtual hosts
#Include conf/extra/httpd-vhosts.conf
按照上面的格式加入一行,你的虚拟主机配置文件,固然,你能够先加入再去写配置ide
Include conf/extra/httpd-vhosts.端口号.conf
#此处填写端口号是为了统一管理,便于记忆网站
以后新建配置文件,在配置文件中输入如下信息spa
touch conf/extra/httpd-vhosts.端口号.conf
NameVirtualHost *:80
Include conf/vhosts/80/*.conf
#上文意思就是,加载全部80端口下的配置文件code
最后,在vhosts文件夹下,创建对应端口的文件夹,在里面创建对应网站的虚拟主机配置信息,具体信息以下:htm
<VirtualHost *:端口号> ServerName 域名 DocumentRoot "代码存放地址" <Directory "代码存放地址"> Options -Indexes FollowSymLinks AllowOverride none Order allow,deny Allow from all DirectoryIndex index.php demo.html </Directory> ErrorLog "logs/域名.error_log" CustomLog "logs/域名.access_log" common </VirtualHost>
至此,虚拟主机的配置就结束了,这样配置的好处是便于管理,对文件映射关系更加直观,下面就是文件引用结构图blog
conf -httpd.conf -extra --httpd-vhosts.端口号.conf ... -vhosts --80 ---www.example.com.conf ... --8080 ---www.text.com.conf ... --端口号 ---www.x.com ---www.xx.com ---www.xx.com ... ...
引用关系以下域名
http.conf{ httpd-vhosts.端口号.conf{ www.example.com.conf .... } .... }