• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
夜真寒
博客园    首页    新随笔    联系   管理    订阅  订阅

Apache虚拟主机配置[转]

① 基于IP地址的虚拟主机配置

Listen 80

DocumentRoot /www/example1

ServerName www.example1.com

DocumentRoot /www/example2

ServerName www.example2.com

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

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

posted @ 2012-03-27 14:23  夜真寒  阅读(285)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3