apache下虚拟主机的配置
几天没更新了,今天配置了下apache虚拟主机,把过程记录下来。安装部分我就不多写了,我是用RPM包安装的apache
#rpm -ivh httpd*
apache的配置文件在/etc/httpd/conf/httpd.conf
web页面文件默认放在/var/html下
虚拟主机配置文件我们单独建立
#echo"Include vhost/vhost.conf " >>/etc/httpd/conf/httpd.conf
#mkdirvhost
#vi vhost.conf
DocumentRoot
ServerName
CustomLogcombined
1 基于IP的虚拟主机的配置
1>相同IP不同端口的配置
#vi vhost.conf
listen 81
listen 82
DocumentRoot /var/www/test81
ServerNametest81
CustomLog /var/www/test81/access_log combined
DocumentRoot /var/www/test82
ServerNametest82
CustomLog /var/www/test82/access_log combined
2>不同IP的配置
可以为eth0配置多个IP,现有IP为192.168.2.164,我们把192.168.2.165也配置上去
# ifconfig eth0:1 192.168.2.165 up
然后修改vhost.conf
#vi vhost.conf
DocumentRoot /var/www/test81
ServerNametest81
CustomLog /var/www/test81/access_log combined
DocumentRoot /var/www/test82
ServerNametest82
CustomLog /var/www/test82/access_log combined
2 基于域名的虚拟主机配置
配置/etc/hosts.conf来解析域名或者DNS服务器来解析
1> 修改/etc/hosts.conf
#vi /etc/hosts.conf
## Do not remove the following line, or various programs
# that require network functionality will fail.
192.168.2.164 www.test1.com
192.168.2.164 www.test2.com
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
#vi /etc/httpd/vhost/vhost.conf
NameVirtualHost 192.168.2.164
DocumentRoot /var/www/test81
ServerNametest81
CustomLog /var/www/test81/access_log combined
DocumentRoot /var/www/test82
ServerNametest82
CustomLog /var/www/test82/access_log combined
重启httpd后即可访问。
2 > 通过DNS服务器实现虚拟主机。
实际上需要为www.test1.com和www.test2.com配置区域文件,DNS的配置这里就不写了,可以参考我的DNS配置那篇文章来配置,httpd的配置同上。分别重启named和httpd后即实现域名的虚拟主机的配置。
页:
[1]