4rr 发表于 2014-4-11 23:41:40

Apache服务器vhost常见配置

本文涵盖了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-(+)-(+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1   
       RewriteCond %{QUERY_STRING} ^(.*)$   
       RewriteRule ^forum-(\w+)-(+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1   
       RewriteCond %{QUERY_STRING} ^(.*)$   
       RewriteRule ^thread-(+)-(+)-(+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1   
       RewriteCond %{QUERY_STRING} ^(.*)$   
       RewriteRule ^group-(+)-(+)\.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-(+)-(+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1   
       RewriteCond %{QUERY_STRING} ^(.*)$   
       RewriteRule ^archiver/(fid|tid)-(+)\.html$ archiver/index.php?action=$1&value=$2&%1   
       RewriteCond %{QUERY_STRING} ^(.*)$   
       RewriteRule ^(+*)-(+)\.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>

页: [1]
查看完整版本: Apache服务器vhost常见配置