码迷,mamicode.com
首页 > Web开发 > 详细

apache配置文件之虚拟主机配置

时间:2015-02-05 14:58:05      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:apache   虚拟主机   httpd.conf   

虚拟主机的配置 
(1)基于IP地址的虚拟主机配置 
Listen 80 
<VirtualHost 172.20.30.40> 
DocumentRoot /www/example1 
ServerName www.example1.com 
</VirtualHost> 
<VirtualHost 172.20.30.50> 
DocumentRoot /www/example2 
ServerName www.example2.org 
</VirtualHost> 


(2) 基于IP和多端口的虚拟主机配置 
Listen 172.20.30.40:80 
Listen 172.20.30.40:8080 
Listen 172.20.30.50:80 
Listen 172.20.30.50:8080 

<VirtualHost 172.20.30.40:80> 
DocumentRoot /www/example1-80 
ServerName www.example1.com 
</VirtualHost> 

<VirtualHost 172.20.30.40:8080> 
DocumentRoot /www/example1-8080 
ServerName www.example1.com 
</VirtualHost> 

<VirtualHost 172.20.30.50:80> 
DocumentRoot /www/example2-80 
ServerName www.example1.org 
</VirtualHost> 

<VirtualHost 172.20.30.50:8080> 
DocumentRoot /www/example2-8080 
ServerName www.example2.org 
</VirtualHost> 

(3)单个IP地址的服务器上基于域名的虚拟主机配置: 
# Ensure that Apache listens on port 80 
Listen 80 

# Listen for virtual host requests on all IP addresses 
NameVirtualHost *:80 

<VirtualHost *:80> 
DocumentRoot /www/example1 
ServerName www.example1.com 
ServerAlias example1.com. *.example1.com 
# Other directives here 
</VirtualHost> 

<VirtualHost *:80> 
DocumentRoot /www/example2 
ServerName www.example2.org 
# Other directives here 
</VirtualHost> 

(4)在多个IP地址的服务器上配置基于域名的虚拟主机: 
Listen 80 

# This is the "main" server running on 172.20.30.40 
ServerName server.domain.com 
DocumentRoot /www/mainserver 

# This is the other address 
NameVirtualHost 172.20.30.50 

<VirtualHost 172.20.30.50> 
DocumentRoot /www/example1 
ServerName www.example1.com 
# Other directives here ... 
</VirtualHost> 

<VirtualHost 172.20.30.50> 
DocumentRoot /www/example2 
ServerName www.example2.org 
# Other directives here ... 
</VirtualHost> 

(5)在不同的端口上运行不同的站点(基于多端口的服务器上配置基于域名的虚拟主机): 
Listen 80 
Listen 8080 

NameVirtualHost 172.20.30.40:80 
NameVirtualHost 172.20.30.40:8080 

<VirtualHost 172.20.30.40:80> 
ServerName www.example1.com 
DocumentRoot /www/domain-80 
</VirtualHost> 

<VirtualHost 172.20.30.40:8080> 
ServerName www.example1.com 
DocumentRoot /www/domain-8080 
</VirtualHost> 

<VirtualHost 172.20.30.40:80> 
ServerName www.example2.org 
DocumentRoot /www/otherdomain-80 
</VirtualHost> 

<VirtualHost 172.20.30.40:8080> 
ServerName www.example2.org 
DocumentRoot /www/otherdomain-8080 
</VirtualHost> 

(6)基于域名和基于IP的混合虚拟主机的配置: 
Listen 80 

NameVirtualHost 172.20.30.40 

<VirtualHost 172.20.30.40> 
DocumentRoot /www/example1 
ServerName www.example1.com 
</VirtualHost> 

<VirtualHost 172.20.30.40> 
DocumentRoot /www/example2 
ServerName www.example2.org 
</VirtualHost> 

<VirtualHost 172.20.30.40> 
DocumentRoot /www/example3 
ServerName www.example3.net 
</VirtualHost> 

apache配置文件之虚拟主机配置

标签:apache   虚拟主机   httpd.conf   

原文地址:http://blog.csdn.net/nyist327/article/details/43527915

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!