apache 虚拟主机配置多IP配置方法

作者:简简单单 2011-05-19

apache 虚拟主机配置多IP配置方法


开启虚拟主机配置文件

对httpd.conf进行设置:

1.注释以下三行
#ServerAdmin
#ServerName
#DocumentRoot
2.去掉mod_proxy.so和mod_proxy_ajp.so的注释
3.#Virtual hosts
#Include conf/extra/httpd-vhosts.conf (查找这行,把前面的#去掉)
/conf/extra/httpd-vhosts.conf

4.打开 /conf/extra/httpd-vhosts.conf
#192.168.1.24为本地Ip
NameVirtualHost 192.168.1.24:80

# php教程项目

DirectoryIndex index.php

ServerAdmin baibiao @gmail.com

ServerName email.sinoepiboly.com

#ServerAlias email.sinoepiboly.com

DocumentRoot D:/phproot/phpmyadmin

==================================================================

方法二:

多二级域名主机开发环境设置说明
第一步 DNS解析实现

找到本机的host文件,一般在 C:WINNTsystem32driversetc,在文件结尾添加:

127.0.0.1 localhost
127.0.0.1 www.com.cn
127.0.0.1 home.com.cn
127.0.0.1 mail.com.cn
127.0.0.1 music.com.cn
127.0.0.1 browseusers.com.cn
127.0.0.1 search.com.cn
127.0.0.1 invite.com.cn
127.0.0.1 rank.com.cn
127.0.0.1 blog.com.cn
127.0.0.1 favorites.com.cn
127.0.0.1 forum.com.cn
127.0.0.1 groups教程.com.cn
127.0.0.1 events.com.cn
127.0.0.1 classifieds.com.cn
127.0.0.1 signup.com.cn
192.168.6.153 i.com.cn
192.168.6.153 x.com.cn

其中
192.168.6.2 i.com.cn
192.168.6.2 x.com.cn
技术人员不作修改,是美工页面专用的

第二步:apache 设置

打开httpd.conf,以music.com.cn为例,其他栏目类似添加,在文件最后加入:

1. 保证
Listen 80

2. 打开注释
NameVirtualHost *:80

3. 在末尾添加

ServerAdmin x_cn@msn.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/music"
ServerName music.com.cn


ServerAdmin x_cn@msn.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/blog"
ServerName blog.com.cn

...

重启即可,Apache虚拟主机设置完成


基于IP地址的虚拟主机配置
Listen 80
DocumentRoot /www/example1
ServerName www.example1.com
DocumentRoot /www/example2
ServerName www.example2.org


基于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

DocumentRoot /www/example1-80
ServerName www.example1.com
DocumentRoot /www/example1-8080
ServerName www.example1.com
DocumentRoot /www/example2-80
ServerName www.example1.org
DocumentRoot /www/example2-8080
ServerName www.example2.org

单个IP地址的服务器上基于域名的虚拟主机配置:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here

在多个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
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here …
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …

在不同的端口上运行不同的站点:
基于多端口的服务器上配置基于域名的虚拟主机。
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
ServerName www.example1.com
DocumentRoot /www/domain-80
ServerName www.example1.com
DocumentRoot /www/domain-8080
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080

基于域名和基于IP的混合虚拟主机的配置:
Listen 80
NameVirtualHost 172.20.30.40
DocumentRoot /www/example1
ServerName www.example1.com
DocumentRoot /www/example2
ServerName www.example2.org
DocumentRoot /www/example3
ServerName www.example3.net

相关文章

精彩推荐