apache中多域名使用同一个ip的方法

作者: Maclean Liu , post on August 10th, 2009 , English Version
【本站文章除注明转载外,均为本站原创编译】
转载请注明:文章转载自: Oracle Clinic – Maclean Liu的个人技术博客 [http://www.oracledatabase12g.com/]
本文标题: apache中多域名使用同一个ip的方法
本文永久地址: http://www.oracledatabase12g.com/archives/apache%e4%b8%ad%e5%a4%9a%e5%9f%9f%e5%90%8d%e4%bd%bf%e7%94%a8%e5%90%8c%e4%b8%80%e4%b8%aaip%e7%9a%84%e6%96%b9%e6%b3%95.html

服务器仅有一个ip ,却需要服务多个域名(实际是多个网站的服务),例如你希望使用同一个台web服务器上同时运行www.example.com与www.example.net。

可在httpd.conf配置文件中(可能位于/etc/httpd/conf或/usr/local/apache/conf目录下),添加以下条目:

Server configuration

# 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.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

apache会就用户访问的域名对应配置中的ServerName选择合适的web目录输出html代码。以上设置中第一项即ServerName www.example.com成为默认选项。若用户访问所指定的域名不符合所有条目时采用默认项,即指向www.example.com。

apache官方的文档: http://httpd.apache.org/docs/2.2/vhosts/examples.html

© 2009, www.oracledatabase12g.com. 版权所有.文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.

暂无相关文章 | No related posts.

1 comment to apache中多域名使用同一个ip的方法

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>