***********
虚拟主机
前提是apache已装好并能正常工作
我用的是httpd-2.2.4.tar.gz
具体安装步骤可查看我的相关文章
一:基于ip地址的虚拟主机配置
#ifconfig eth0:0 192.168.60.202 up
#ifconfig eth0:1 192.168.60.203 up
#ping 192.168.60.202
#ping 192.168.60.203
#vi httpd.conf
添加以下内容
ServerAdmin
DocumentRoot /usr/local/apache2/vhost1
ServerName vhost1.hdqh.net
ErrorLog logs/vhost1._log
CustomLog logs/vhost1._log common
ServerAdmin
DocumentRoot /usr/local/apache2/vhost2
ServerName vhost2.hdqh.net
ErrorLog logs/vhost2._log
CustomLog logs/vhost2._log common
#mkdir /usr/local/apache2/vhost1
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost1
listen 192.168.60.202
#mkdir /usr/local/apache2/vhost2
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost2
listen 192.168.60.203
#/usr/local/apache2/bin/apachectl restart
测试
二:基于端口的虚拟主机配置
#vi httpd.conf
添加以下内容
Listen 88
Listen 99
ServerAdmin
DocumentRoot /usr/local/apache2/vhost1
ServerName vhost1.hdqh.net
ErrorLog logs/vhost1._log
CustomLog logs/vhost1._log common
ServerAdmin
DocumentRoot /usr/local/apache2/vhost2
ServerName vhost2.hdqh.net
ErrorLog logs/vhost2._log
CustomLog logs/vhost2._log common
#mkdir /usr/local/apache2/vhost1
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost1
listen 88
#mkdir /usr/local/apache2/vhost2
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost2
listen 99
#/usr/local/apache2/bin/apachectl restart
测试
三:基于域名的虚拟主机配置
在dns服务器上建立区域
xxx.com
yyy.net
#vi /etc/named.conf
zone "xxx.com" IN {
type master;
file "xxx.com.zone";
};
zone "yyy.net" IN {
type master;
file "yyy.net.zone";
};
及相关区域文件
#vi /var/named/xxx.com.zone
$TTL 86400
$ORIGIN xxx.com.
@ 1D IN SOA @ root ( 42 3H 15M 1W 1D )
1D IN NS @
1D IN A 192.168.60.201
www IN A 192.168.60.201
#vi /var/named/yyy.net.zone
$TTL 86400
$ORIGIN yyy.net.
@ 1D IN SOA @ root ( 42 3H 15M 1W 1D )
1D IN NS @
1D IN A 192.168.60.201
www IN A 192.168.60.201
#vi httpd.conf
NameVirtualHost 192.168.60.201:80
ServerAdmin
DocumentRoot /usr/local/apache2/vhost1
ServerName
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
ServerAdmin
DocumentRoot /usr/local/apache2/vhost2
ServerName
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
#mkdir /usr/local/apache2/vhost1
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost1
#mkdir /usr/local/apache2/vhost2
#cd /usr/local/apache2/vhost1
#vi index.html
添加以下内容
vhost2