ITPub博客

首页 > IT基础架构 > 网络安全 > Apache 配置各种虚拟主机实践(转)

Apache 配置各种虚拟主机实践(转)

原创 网络安全 作者:ba 时间:2007-08-16 14:38:40 0 删除 编辑
Apache 配置各种虚拟主机实践(转)[@more@]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/"


……
……

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10617731/viewspace-961910/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    1621
  • 访问量
    4429915