Apache服务器虚拟主机(vhost)常见配置

简介:
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://dgd2010.blog.51cto.com/1539422/1394105

本文涵盖了Apache服务器中常用的vhost配置方法,由于时间关系不在文中进行讲解,仅供参考。

#   
# 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:http://httpd.apache.org/docs/2.2/vhosts/>
# 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 dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/web1.vtest.org"    
   ServerName web1.vtest.org    
#   ServerAlias web1.vtest.org    
   <Directory "C:/WANMP/apps/web1.vtest.org">    
       Options Indexes    
       Order allow,deny    
       IndexOptions Name Charset=UTF-8    
       Allow from all    
   </Directory>    
   ErrorLog "logs/web1.vtest.org-error.log"    
   CustomLog "logs/web1.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/web2.vtest.org"    
   ServerName web2.vtest.org    
   ErrorLog "logs/web2.vtest.org-error.log"    
   CustomLog "logs/web2.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/bbs.vtest.org"    
   ServerName bbs.vtest.org    
   ErrorLog "logs/bbs.vtest.org-error.log"    
   CustomLog "logs/bbs.vtest.org-access.log" common    
   <Directory C:\WANMP\apps\bbs.vtest.org/ >    
       Options FollowSymLinks    
       AllowOverride All    
       #    Order deny,allow    
       #    Deny from all    
       RewriteEngine On    
       RewriteBase /    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1    
       RewriteCond %{QUERY_STRING} ^(.*)$    
       RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1shy.gif2&%1    
   </Directory>    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/sns.vtest.org"    
   ServerName sns.vtest.org    
   ErrorLog "logs/sns.vtest.org-error.log"    
   CustomLog "logs/sns.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/www.vtest.org"    
   ServerName www.vtest.org
   ErrorLog "logs/www.vtest.org-error.log"    
   CustomLog "logs/www.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/sql.vtest.org"    
   ServerName sql.vtest.org    
   ErrorLog "logs/sql.vtest.org-error.log"    
   CustomLog "logs/sql.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/dns.vtest.org"    
   ServerName dns.vtest.org    
   ErrorLog "logs/dns.vtest.org-error.log"    
   CustomLog "logs/dns.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/php.vtest.org"    
   ServerName php.vtest.org    
   ErrorLog "logs/php.vtest.org-error.log"    
   CustomLog "logs/php.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   DocumentRoot "C:/WANMP/apps/tmp.vtest.org"    
   ServerName file.vtest.org    
   ErrorLog "logs/file.vtest.org-error.log"    
   CustomLog "logs/file.vtest.org-access.log" common    
   <Directory "C:/WANMP/apps/tmp.vtest.org">    
       Options Indexes    
       Order allow,deny    
       IndexOptions Name Charset=UTF-8    
       Allow from all    
   </Directory>    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   ServerName proxy.vtest.org    
   ProxyPass / http://172.16.169.52/
   ProxyPassReverse / http://172.16.169.52/
   ErrorLog "logs/proxy.vtest.org-error.log"    
   CustomLog "logs/proxy.vtest.org-access.log" common    
</VirtualHost>    
<VirtualHost *:80>    
   ServerAdmin dgdenterprise@gmail.com
   ServerName main.deploy.elp    
   DocumentRoot "C:/WANMP/apps/main.vtest.org"    
   # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    
   LogFormat "%h %l %u %t \"%r\" %>s %b" vhostcommon    
   CustomLog logs/main.deploy.elp-access.log vhostcommon    
   ErrorLog "logs/main.deploy.elp-error.log"    
</VirtualHost>

本文出自 “通信,我的最爱” 博客,请务必保留此出处http://dgd2010.blog.51cto.com/1539422/1394105

目录
相关文章
|
6月前
|
弹性计算 ice
阿里云4核8G云服务器配置价格:热门ECS实例及CPU处理器型号说明
阿里云2025年4核8G服务器配置价格汇总,涵盖经济型e实例、计算型c9i等热门ECS实例,CPU含Intel Xeon及AMD EPYC系列,月费159元起,年付低至1578元,按小时计费0.45元起,实际购买享折扣优惠。
2221 1
|
6月前
|
弹性计算 定位技术 数据中心
阿里云服务器配置选择方法:付费类型、地域及CPU内存配置全解析
阿里云服务器怎么选?2025最新指南:就近选择地域,降低延迟;长期使用选包年包月,短期灵活选按量付费;企业选2核4G5M仅199元/年,个人选2核2G3M低至99元/年,高性价比爆款推荐,轻松上云。
677 11
|
6月前
|
存储 弹性计算 网络协议
超详细的阿里云服务器购买流程,ECS自定义购买配置教程
本文详细图解阿里云ECS服务器自定义购买全流程,涵盖付费模式、地域选择、网络配置、实例规格、镜像、存储、安全组及登录设置等核心步骤,助您轻松掌握专业级云服务器搭建方法。
|
6月前
|
存储 弹性计算 监控
阿里云渠道商:如何挑选阿里云服务器配置?
本文详解通用型、计算型、内存型等实例适用场景,结合性能评估与成本优化策略,助力用户按需选择。以日均1万访问企业网站为例,2核4G+3M带宽月费约200元,性价比高。合理配置更省钱。
|
6月前
|
弹性计算
阿里云ECS云服务器8核16G配置收费价格,多种ECS实例CPU及费用清单
阿里云8核16G云服务器价格因实例类型而异。计算型c9i约743元/月,一年6450元(7折);通用算力型u1仅673元/月,一年4225元(5.1折)。实际价格享时长折扣,详情见ECS官网。
|
6月前
|
弹性计算 Windows
阿里云香港服务器收费价格:香港ECS和轻量应用服务器配置介绍
2025年阿里云香港服务器优惠汇总:ECS 2核4G+5M带宽仅199元/年;轻量服务器30M带宽24元/月起,200M峰值带宽25元/月起。轻量性价比高,适合个人及中小企业建站、跨境业务,具体配置价格详见官方活动页。
2980 1
|
7月前
|
弹性计算 定位技术 数据中心
阿里云服务器选择方法:配置、地域及付费模式全解析
2025阿里云服务器选购指南:就近选择地域以降低延迟,企业用户优选2核4G5M带宽u1实例,仅199元/年;个人用户可选2核2G3M带宽ECS,99元/年起。长期稳定业务选包年包月,短期或波动场景用按量付费,轻松搭建网站首选高性价比配置。

热门文章

最新文章

推荐镜像

更多
下一篇
开通oss服务