您的位置:首页 > 运维架构 > Apache

apache服务器如何实现多IP配置的方法实例

2011-05-19 16:40 806 查看
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项目

<VirtualHost 192.168.1.24:80>

<Directory "D:/phproot/phpmyadmin">

DirectoryIndex index.php

</Directory>

ServerAdmin baibiao @gmail.com

ServerName email.sinoepiboly.com

#ServerAlias email.sinoepiboly.com

DocumentRoot D:/phproot/phpmyadmin

</VirtualHost>

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

方法二:

多二级域名主机开发环境设置说明

第一步 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. 在末尾添加

<VirtualHost *:80>

ServerAdmin x_cn@msn.com

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/music"

ServerName www.3ppt.com

</VirtualHost>

<VirtualHost *:80>

ServerAdmin x_cn@msn.com

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/blog"

ServerName blog.com.cn

</VirtualHost>

...

重启即可,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.3ppt.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
本文出自 “完美主义者” 博客,请务必保留此出处http://kokoxoxo.blog.51cto.com/3115159/568691
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: