Apache虚拟主机的配置
本文最后更新于 5820 天前,其中的信息可能已经有所发展或是发生改变。

虚拟主机的配置

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

评论

  1. 16年前
    2008-4-21 22:07:25

    不错的文章

  2. Nice
    16年前
    2008-4-22 9:47:36

    收了

  3. 7f
    15年前
    2009-8-13 14:21:26

    不错 谢谢指导

  4. 13年前
    2011-2-21 17:40:39

    写得不错,收了。。

  5. 12年前
    2011-10-26 11:22:37

    正在学习apache配置…

  6. 啊冰
    12年前
    2011-12-26 17:51:29

    可以在每个配置的后面加一个注释,这样就一目了然了。

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇