基于端口
不同端口,相同ip,相同域名
vi /usr/local/httpd/conf/httpd.conf
在listen修改和添加一个
Listen 192.168.6.1:80
Listen 192.168.6.1:81
开启虚拟主机模块
Include conf/extra/httpd-vhosts.conf
去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
修改为以下内容
<VirtualHost 192.168.6.1:80>
ServerAdmin
DocumentRoot "/usr/local/httpd/htdocs/a"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>
<VirtualHost 192.168.6.1:81>
ServerAdmin
DocumentRoot "/usr/local/httpd/htdocs/b"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>
基于ip
不同IP,不同域名,相同端口;基于IP的虚拟主机
首先你要确定你有多个ip
vim /usr/local/httpd/conf/httpd.conf
在listen修改和添加一个
Listen 192.168.6.1:80
Listen 192.168.6.100:80
开启虚拟主机模块
Include conf/extra/httpd-vhosts.conf
去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
修改为
<VirtualHost 192.168.6.1:80>
ServerAdmin
DocumentRoot "/usr/local/httpd/htdocs/a"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>
<VirtualHost 192.168.6.100:80>
ServerAdmin
DocumentRoot "/usr/local/httpd/htdocs/b"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>
基于域名
相同ip,相同端口,不同域名
vim /usr/local/httpd/conf/httpd.conf
在listen修改和添加一个
Listen 192.168.6.1:80
开启虚拟主机模块
Include conf/extra/httpd-vhosts.conf
去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
修改为
<VirtualHost *:80>
DocumentRoot "/usr/local/httpd/htdocs/a"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/usr/local/httpd/htdocs/b"
ServerName
ErrorLog "logs/-error_log"
CustomLog "logs/-access_log" common
</VirtualHost>