基于IP地址的虚拟主机配置,在一台主机上有多个IP的情况。
ifconfig eth0:2 192.168.2.6 netmask 255.255.255.0 up
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site1
ServerName sit1.com
ErrorLog logs/sit1.com-error_log
CustomLog logs/sit1-access_log common
<Directory /var/www/site1>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.6:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site2
ServerName sit2.com
ErrorLog logs/sit2.com-error_log
CustomLog logs/sit2-access_log common
<Directory /var/www/site2>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
基于主机头的虚拟主机配置,Web服务器上只有一个IP,
服务器根据客户端请求的host判断请求的是哪一个web站点。
httpd.conf中要打开下面的配置:
NameVirtualHost 192.168.2.5:80
假设服务器配置两个站点 tec.test.com mkt.test.com,ip 为192.168.2.5
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site1
ServerName tec.test.com
ErrorLog logs/sit1.com-error_log
CustomLog logs/sit1-access_log common
<Directory /var/www/site1>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site2
ServerName mkt.test.com
ErrorLog logs/sit2.com-error_log
CustomLog logs/sit2-access_log common
<Directory /var/www/site2>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
如果没有配置DNS,可以修改客服端host文件来测试。
通过tec.test.com访问的则为/var/www/site1的内容。
通过mkt.test.com访问的则为/var/www/site2的内容。
不同的IP对应不同的网站内容,客户端可以通过IP访问不同的网页内容。
为服务器添加多个IP地址:
ifconfig eth0:2 192.168.2.6 netmask 255.255.255.0 up
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site1
ServerName sit1.com
ErrorLog logs/sit1.com-error_log
CustomLog logs/sit1-access_log common
<Directory /var/www/site1>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.6:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site2
ServerName sit2.com
ErrorLog logs/sit2.com-error_log
CustomLog logs/sit2-access_log common
<Directory /var/www/site2>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
基于主机头的虚拟主机配置,Web服务器上只有一个IP,
服务器根据客户端请求的host判断请求的是哪一个web站点。
httpd.conf中要打开下面的配置:
NameVirtualHost 192.168.2.5:80
假设服务器配置两个站点 tec.test.com mkt.test.com,ip 为192.168.2.5
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site1
ServerName tec.test.com
ErrorLog logs/sit1.com-error_log
CustomLog logs/sit1-access_log common
<Directory /var/www/site1>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.5:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/site2
ServerName mkt.test.com
ErrorLog logs/sit2.com-error_log
CustomLog logs/sit2-access_log common
<Directory /var/www/site2>
Options Indexes FollowSymLinks
order deny,allow
allow from all
</Directory>
</VirtualHost>
如果没有配置DNS,可以修改客服端host文件来测试。
通过tec.test.com访问的则为/var/www/site1的内容。
通过mkt.test.com访问的则为/var/www/site2的内容。