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


相关文章
|
10天前
|
人工智能 API 开发者
FastAPI开发者福音!FastAPI-MCP:将FastAPI秒变MCP服务器的开源神器,无需配置自动转换!
FastAPI-MCP是一款能将FastAPI应用端点自动转换为符合模型上下文协议(MCP)的开源工具,支持零配置自动发现接口并保留完整文档和模式定义。
265 14
FastAPI开发者福音!FastAPI-MCP:将FastAPI秒变MCP服务器的开源神器,无需配置自动转换!
|
2月前
|
存储 缓存 网络协议
阿里云特惠云服务器99元与199元配置与性能和适用场景解析:高性价比之选
2025年,阿里云长效特惠活动继续推出两款极具吸引力的特惠云服务器套餐:99元1年的经济型e实例2核2G云服务器和199元1年的通用算力型u1实例2核4G云服务器。这两款云服务器不仅价格亲民,而且性能稳定可靠,为入门级用户和普通企业级用户提供了理想的选择。本文将对这两款云服务器进行深度剖析,包括配置介绍、实例规格、使用场景、性能表现以及购买策略等方面,帮助用户更好地了解这两款云服务器,以供参考和选择。
|
1天前
|
存储 缓存 监控
阿里云服务器配置与云盘容量选择参考:实例规格、云盘等相关配置选择解析
对于初次接触云服务器的用户来说,面对众多配置选项和云盘容量选择,可能会不知道如何选择。有些用户甚至不清楚云服务器应该购买多大容量的云盘,也不知道哪一款配置的云服务器更适合自己的业务。本文将详细探讨这两个问题,并结合阿里云服务器的特点,为您提供一份云服务器配置与云盘容量选择指南,以供了解和选择参考。
|
14天前
|
Ubuntu 安全 网络安全
在Ubuntu系统下使用vsftpd配置FTP服务器的步骤
以上就是在Ubuntu系统下使用vsftpd配置FTP服务器的步骤。这些步骤都是基础的,但足够让你建立一个简单的FTP服务器。如果你需要更高级的功能,例如SSL加密、虚拟用户等,你可能需要进一步研究vsftpd的配置选项。
64 13
|
23天前
|
存储 监控 API
【Azure App Service】分享使用Python Code获取App Service的服务器日志记录管理配置信息
本文介绍了如何通过Python代码获取App Service中“Web服务器日志记录”的配置状态。借助`azure-mgmt-web` SDK,可通过初始化`WebSiteManagementClient`对象、调用`get_configuration`方法来查看`http_logging_enabled`的值,从而判断日志记录是否启用及存储方式(关闭、存储或文件系统)。示例代码详细展示了实现步骤,并附有执行结果与官方文档参考链接,帮助开发者快速定位和解决问题。
76 24
|
16天前
|
存储 弹性计算 数据处理
阿里云服务器2核8G、4核16G、8核32G配置热门实例价格、性能与场景全攻略
2核8G/4核16G/8核32G配置的阿里云服务器在阿里云活动中目前有经济型e、通用算力型u1、通用型c7、通用型g8i和通用型g8y五种实例可选,虽然配置相同,但是这些实例规格之间的价格差别是很大的。面对不同配置和类型的云服务器实例,有的新手用户往往因为不知道他们之间的区别,所以不知道如何选择。本文将针对常见的2核8G、4核16G、8核32G配置,深入剖析阿里云服务器中的经济型e、通用算力型u1、通用型g7及通用型g8y实例,以供大家参考和选择。
|
22天前
|
Ubuntu 网络协议
在Ubuntu 18.04服务器上配置双网口以接入互联网
总结一下,配置双网口在Ubuntu 18.04服务器就像一场冒险游戏,你小心翼翼地从查看网络布局开始,铺设新线路,最后得到了通往互联网的双重通道。祝你在网络世界的冒险旅程中更上一层楼!
58 11
|
22天前
|
存储 弹性计算 固态存储
阿里云服务器配置怎么选择?根据用户类型及使用场景配置推荐
如何选择阿里云服务器配置?2025年全解析!个人用户可选68元/年的轻量应用服务器(2核2G、200M带宽),企业用户推荐199元/年的ECS通用算力型u1实例(2核4G、5M带宽)。针对不同需求,还有内存型、计算型、高主频型及GPU服务器等多规格实例。带宽选择需根据访问量,小流量应用3M即可,高流量建议10M起步。存储方面,系统盘40GB够用,数据盘按需选择ESSD或SSD云盘,确保I/O性能满足业务需求。阿小云为你整理最新攻略,助你高效选型!
|
22天前
|
存储 弹性计算 人工智能
阿里云服务器2核8G/4核16G/8核32G配置热门实例规格对比与选购指南
如果我们是计划购买2核8G/4核16G/8核32G配置的阿里云服务器,在阿里云活动中一般会有经济型e、通用算力型u1、通用型g7、通用型g8i和通用型g8y几种常见的实例规格可选,尽管这些实例在配置上相似,但它们在性能、价格以及适用场景上存在显著差异。本文将深入解析这些实例规格的性能特点、价格差异及适用场景,为用户在阿里云服务器购买时提供详实的参考依据。
|
25天前
|
弹性计算 固态存储 ice
阿里云服务器ECS内存型2核16G、4核32G和8核64G配置实例、费用和性能参数表
本文整理了2025年阿里云服务器租赁价格表,涵盖2核16G、4核32G和8核64G配置收费标准。CPU内存比为1:8,提供多种实例规格如ECS内存型r8i、通用算力型u1等。价格由CPU内存、公网带宽及系统盘组成,支持优惠折扣(年付6.7折起)。文中详细列出各配置参考价格、公网带宽与系统盘收费,并对比不同实例规格性能,如Intel Xeon和AMD EPYC处理器系列,帮助用户选择高性价比方案。具体价格以阿里云官网为准。
98 4

推荐镜像

更多
下一篇
oss创建bucket