/ 中存储网

Apache虚拟主机配置教程

2014-04-19 13:34:01 来源:IT技术网
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/"

……

……