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

简介:

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

注意:如果虚拟主机的端口不是默认的80,则比如添加额外的Listen <端口号>指令。

此处以Apache2.4为例:

Listen 6001

Listen 6003

#NameVirtualHost *:6001

#NameVirtualHost *:6003

<VirtualHost *:6001>

   DocumentRoot "/data/svc/www"

   ServerName localhost

   <Directory "/data/svc/www">

       Options Indexes

       Order allow,deny

       Allow from all

   </Directory>

   ErrorLog "logs/port_6001-error.log"

   CustomLog "logs/port_6001-access.log" common

</VirtualHost>


<VirtualHost *:6003>

   DocumentRoot "/data/qy/www"

   ServerName localhost

   <Directory "/data/qy/www">

       Options Indexes

       Order allow,deny

       Allow from all

   </Directory>

   ErrorLog "logs/port_6003-error.log"

   CustomLog "logs/port_6003-access.log" common

</VirtualHost>

-------------------------------------------------------------------------------------

注意:有时如果httpd.conf主配置文件先前没有设定,可能会遇到“Forbidden You don't have permission to access / on this server.”的错误提示,此时需要修改httpd.conf配置文件,修改如下:

<Directory />

    Options Indexes FollowSymLinks

    AllowOverride all

    Order deny,allow

    Allow from all

</Directory>

-------------------------------------------------------------------------------------

#   
# 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>

tag:apache,虚拟主机配置, 虚拟主机,添加vhost

--end--



本文转自 urey_pp 51CTO博客,原文链接:http://blog.51cto.com/dgd2010/1394105,如需转载请自行联系原作者


相关文章
|
11天前
|
消息中间件 安全 Unix
SSH配置多台服务器之间的免密登陆以及登陆别名
SSH配置多台服务器之间的免密登陆以及登陆别名
20 1
|
13天前
|
网络安全 Apache
Apache服务器安装SSL证书
Apache服务器安装SSL证书
18 0
|
25天前
|
弹性计算
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
2024年阿里云服务器的优惠价格新鲜出炉,有特惠云服务器也有普通优惠价格,本文为大家整理汇总了2024年阿里云服务器的优惠价格,包含特惠云服务器和其他配置云服务器的优惠价格。以便大家了解自己想购买的云服务器选择不同实例规格和带宽情况下的价格,仅供参考。
2024年阿里云服务器不同实例规格与配置实时优惠价格整理与分享
|
4天前
|
存储 Java 网络安全
ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
【4月更文挑战第10天】ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
12 1
|
8天前
|
存储 弹性计算 安全
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
2核2G、2核4G配置是很多个人和企业建站以及部署中小型的web应用等场景时首选的云服务器配置,这些配置的租用价格也是用户非常关心的问题,本文为大家整理汇总了2024年阿里云服务器2核2G、2核4G配置不同实例规格及地域之间的收费标准,同时整理了这些配置最新活动价格,以供大家参考和选择。
阿里云服务器2核2G、2核4G配置最新租用收费标准及活动价格参考
|
10天前
|
域名解析 网络协议 应用服务中间件
阿里云服务器配置免费https服务
阿里云服务器配置免费https服务
|
13天前
|
安全 关系型数据库 MySQL
国产麒麟服务器等保二级 配置规范(一)
国产麒麟服务器等保二级 配置规范(一)
32 0
|
13天前
|
数据采集
robots.txt配置 减小服务器压力
robots.txt配置 减小服务器压力
13 0
|
24天前
|
网络协议 Linux 网络安全
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
Linux服务器DNS服务器配置实现bind的正向解释和反向解释
17 0
|
26天前
|
弹性计算 网络安全 虚拟化
ECS数据问题之升级配置预防数据丢失如何解决
ECS(Elastic Compute Service,弹性计算服务)是云计算服务提供商提供的一种基础云服务,允许用户在云端获取和配置虚拟服务器。以下是ECS服务使用中的一些常见问题及其解答的合集:

推荐镜像

更多