apache基于域名的虚拟主机配置方法

五月 10th, 2010 Posted in Apache | 阅读次数: 410 次

Author:gaojinbo

Time:2010-5-10

我们很多时候需要配置apache虚拟主机,以下文档可以很方便地配置出自己想要的虚拟主机,以下方法仅供大家参考!apache虚拟主机配置

 

基于域名的虚拟主机的访问

1.  vi /etc/http/conf/httpd.conf
更改虚拟主机部分为:
NameVirtualHost *:80

<VirtualHost www1.example.com>
DocumentRoot /var/www/html/website1
ServerName www1.example.com
</VirtualHost>

<VirtualHost www2.example.com>
DocumentRoot /var/www/html/website2
ServerName www2.example.com
</VirtualHost>
(注:以上设置中NameVirtualHost不可以省略)

 

2.  创建目录以及页面文件:
mkdir –p /var/www/html/website1
mkdir –p /var/www/html/website2
cd /var/www/html/website1
echo “website1” >index.html

cd /var/www/html/website2
echo “website2” >index.html

 

3.  完成以上设置后,可以通过以下方式访问:
1)打开浏览器
2)输入http://www1.example.com 以及 http://www2.example.com

 

完成!

相关日志:

Tags:

3 Responses to “apache基于域名的虚拟主机配置方法”

  1. Help for Panic Attacks Says:

    Favourite Sites…

    [...]I like to honor other websites on the web, even if they are not related to my site, by linking to them. Below are some websites I think are worth checking out http://www.panicattackstreatmentcure.net/links/…...


  2. 明湖 Says:

    我的和你的不一样:
    我的是
    /etc/apache2/*
    你的是什么版本的啊?


  3. Mercedes Solbriller Says:

    Blogs you should be reading……

    [...]Here is a great blog you might find Interesting that we encourage you[...]……


留下您的脚印