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,如需转载请自行联系原作者


相关文章
|
1天前
|
安全 Linux 网络安全
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
|
1天前
|
数据库 数据中心 虚拟化
云服务器和虚拟主机有什么区别
总的来说,云服务器提供更高级别的灵活性、控制和资源隔离,适用于需要定制化和更大资源的应用程序。虚拟主机是一种经济实惠的共享托管解决方案,适用于小型项目和个人网站。选择哪种服务取决于你的需求、预算和技术要求。
9 2
|
8天前
|
弹性计算 Shell Apache
某时间段访问apache 服务器的请求IP
【4月更文挑战第29天】
15 2
|
8天前
|
弹性计算 Shell Apache
|
14天前
|
负载均衡 Ubuntu 应用服务中间件
Apache(mod_proxy)+Tomcat负载均衡配置
Apache(mod_proxy)+Tomcat负载均衡配置
|
14天前
|
运维 Apache 数据安全/隐私保护
CentOS6.5搭建SVN服务器(Apache+SVN)
CentOS6.5搭建SVN服务器(Apache+SVN)
|
18天前
|
缓存 负载均衡 网络安全
如何配置Apache的反向代理
如何配置Apache的反向代理
|
18天前
|
网络安全 API Apache
本地快速部署Apache服务器并使用内网穿透实现远程访问
本地快速部署Apache服务器并使用内网穿透实现远程访问
|
负载均衡 应用服务中间件 Apache
关于配置并发访问的服务器apache、nginx
一、 apache,nginx比较     关于Apache与Nginx的优势比较  (apache计算密集型   nginx io密集型  各有优势,不存在谁取代谁) 二、nginx 基于nginx的tomcat负载均衡和集群(超简单)  侧重点简单配置,缺点多人访问时,session ...
1233 0
|
2月前
|
消息中间件 API Apache
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会
本文整理自阿里云开源大数据平台徐榜江 (雪尽),关于阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会。
1615 2
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会

热门文章

最新文章

推荐镜像

更多