首 页文章中心

Linux学习网

您的位置Linux学习网 > Linux服务器应用 > 文章内容

Apache 配置各种虚拟主机实践

作者:佚名  来源:不详  发布时间:2008-6-26 8:45:00
1.实践环境:
Red Hat Enterprise Linux AS release 4 (Nahant Update 3)
Server version: Apache/1.3.34 (Unix)
Server built: Sep 26 2006 15:06:28

2.基于域名方式的虚拟主机:
vi httpd.conf
……
……
BindAddress *
指示用所有地址都可以监听虚拟主机的请求
NameVirtualHost *:80
使用基于域名方式的虚拟主机

ServerName mail.ok.com
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"


ServerName mail.test.com
DocumentRoot /opt/apache/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"

……
……

小结:这种基于域名方式的配置适合与用在服务器只有一个公网ip的情况。每个虚拟主机必须设置指令块,块中可以添加除了ServerType,Startservers,MaxSpareserver,MinSpareserver,MaxRequestsPerchild,BindAddress,Lister,PidFile,TypeConfig,ServerRoot,NameVirtualHost之外的任何命令。这种方式必须依赖DNS的解析。

3.基于IP地址的虚拟主机

vi httpd.conf
……
……
BindAddress *
指示用所有地址都可以监听虚拟主机的请求
#NameVirtualHost *:80
使用基于域名方式的虚拟主机

ServerName mail.ok.com
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"


ServerName mail.test.com
DocumentRoot /opt/apache/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"


……
……

4.基于端口的虚拟主机

vi httpd.conf
……
……
BindAddress *
指示用所有地址都可以监听虚拟主机的请求
Listen 8080
让apache监听8080端口,这里是采用ip:port模式。
#NameVirtualHost 192.168.0.246:8080
使用基于域名方式的虚拟主机,如果要用域名:port模式的话这里要打开

ServerName mail.ok.com
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"


ServerName mail.test.com
DocumentRoot /opt/apache/html
ScriptAlias /cgi-bin/ "/opt/apache/cgi-bin/"


……
……
收藏本页到: 365Key | del.icio.us | | 添加到雅虎收藏+
  • 网站帮助 - 广告合作 - 网站地图