红联Linux门户
Linux帮助

Apache 配置各种虚拟主机实践

发布时间:2006-10-21 01:06:21来源:红联作者:舍其里奥
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/"


……
……
文章评论

共有 1 条评论

  1. lkongl 于 2006-11-14 11:13:04发表:

    :0L