广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 13891 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
johnroyer 手机
个人头像
个人文章 个人相簿 个人日记 个人地图
特殊贡献奖
小有名气
级别: 小有名气 该用户目前不上站
推文 x8 鲜花 x505
分享: 转寄此文章 Facebook Plurk Twitter 版主评分版主评分 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[FreeBSD][发表] Apache Virtual Host
精华文章
多注意的话
可以发现有些网址非常特别

google.com...
mail.google.com
picasaweb.google.com


而且 ping 一下还会发现这些 DomainName 都连到同一个 IP
这就是 Apache Virtual Host 的功能啦
当然 Google 不是这样做的啦………举例而已

要启动 Apache 的 Virtual Host 功能
首先开启 /usr/local/etc/apache22/httpd.conf
在任意地方加入以下设定

复制程式
# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf

由上面的设定可以看出
这一段会使 Apache 去读取 extra/httpd-vhosts.conf
而 httpd-vhosts.conf 就是 Virtual Host 的设定档

当然也可以直接写在 http.conf 内
但是为了方便管理以及日后的维护
通常都会放在 extra/httpd-vhosts.conf


接下来看看 httpd-vhosts.conf 里面写了些什么

复制程式
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:[url]http://httpd.apache.org/docs/2.2/vhosts/>[/url]
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

 VirtualHost example:
 Almost any Apache directive may go into a VirtualHost container.
 The first VirtualHost section is used for all requests that do not
 match a ServerName or ServerAlias in any <VirtualHost> block.

<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host.example.com[/email]
    DocumentRoot /www/docs/dummy-host.example.com
    ServerName dummy-host.example.com
    ServerAlias [url]www.dummy-host.example.com[/url]
    ErrorLog /var/log/dummy-host.example.com-error_log
    CustomLog /var/log/dummy-host.example.com-access_log common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
    DocumentRoot /www/docs/dummy-host2.example.com
    ServerName dummy-host2.example.com
    ErrorLog /var/log/dummy-host2.example.com-error_log
    CustomLog /var/log/dummy-host2.example.com-access_log common
</VirtualHost>

可以看出每个不同的 vhost 都被包在标签中
<VirtualHost *:80>
......
</VirtualHost>

参数说明:
ServerAdmin:此 vhost 的管理员电子邮件
DocumentRoot:连结到此 vhost 时,会以哪个目录当作预设的根目录
ServerName:vhost 的 DNS
ServerAlias:vhost 的 Alias
ErrorLog:对于这个 vhost 错误记录档的储存位置
CustomLog:对于这个 vhost 记录档的储存位置

设定好之后
别忘记将原本做为参考用的二个 vhost 删除或设为注解
然后重新启动 appachectl restart

//----------------------------------------------------------------

再补上一招管理密技
用的方法一样是「include」
你把的所有 vhost 设定分别储存成档案存放在其他目录

复制程式
NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin [email]mail@mail.com[/email]
        DocumentRoot /usr/local/www/apache22/data/
        ServerName 192.168.0.1
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>

Include /usr/local/etc/apache22/vhosts/*.conf

然后其他的设定档分别储存到 /usr/local/etc/apache22/vhosts/
档名为 vhost1.mychat.com.conf
    vhost2.mychat.com.conf



vhost1.mychat.com.conf:
复制程式
<VirtualHost *:80>
        ServerAdmin [email]mail1@mychat.com[/email]
        DocumentRoot /usr/local/www/apache22/data/vhost1/
        ServerName vhost1.mychat.com.conf
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/vhost1/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>





vhost2.mychat.com.conf
复制程式
<VirtualHost *:80>
        ServerAdmin [email]mail2@mychat.com[/email]
        DocumentRoot /usr/local/www/apache22/data/vhost2/
        ServerName vhost2.mychat.com.conf
        ErrorLog /var/log/httpd-error.log
        CustomLog /var/log/httpd-access.log combined

        <Directory />
        AllowOverride None
        Order Deny,Allow
        Deny from all
        </Directory>

        <Directory "/usr/local/www/apache22/data/vhost2/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        </Directory>
</VirtualHost>


这样管理上会方便许多

原文:Zeroplex 生活随笔: FreeBSD Apache Virtual Host
http://zeroplex.blogspot.com/2008/05/...irtual-host.html

请多指教


[ 此文章被johnroyer在2008-08-18 03:13重新编辑 ]

此文章被评分,最近评分记录
财富:250 (by andyz)



My Blog : Zeroplex
Plurk : Zeroplex
献花 x0 回到顶端 [楼 主] From: | Posted:2006-10-17 02:20 |
singulai
数位造型
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x0 鲜花 x0
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

解说清楚,实做简单,感谢。


献花 x0 回到顶端 [1 楼] From:未知地址 | Posted:2008-09-01 11:02 |
mnbmnb5266
个人文章 个人相簿 个人日记 个人地图
小有名气
级别: 小有名气 该用户目前不上站
推文 x5 鲜花 x46
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

谢谢大大的程式分享,先看看管不管用再说


我的收藏
https://pan.baidu.com/s/1QUJ9lr_VzxXKRJAlBJgUQA
提取码:am2c
献花 x0 回到顶端 [2 楼] From:加拿大Rogers | Posted:2010-08-21 22:40 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.021366 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言