Apache配置虚拟目录和多主机头
呃,相当古老的话题了,不过网上的资料实在是太坑爹,无奈只能自己动手做个备忘了。。。
这里不提虚拟目录和主机头的区别了,不懂得童鞋去面壁思过吧
多个虚拟目录
首先把Apache安装到D:\Program Files\Apache2.2目录下,端口号设置为8080,安装完成后默认的网站根目录为D:\Program Files\Apache2.2\htdocs,通常我们可以在htdocs下面建立个文件夹MySite,然后在浏览器输入:http://localhost:8080/MySite 这样就可以看到我们自己的站点了。然而有时我们想把站点放到其它目录下面,这时就需要配置虚拟目录了
比如我们在D盘建立如下文件夹D:\Code\WebSite,然后通过http://localhost:8080/DemoSite来访问这个站点
打开httpd.conf文件,搜索<IfModule alias_module> 节点,然后在节点内输入以下内容:


#下面是虚拟目录声明格式
#Alias用来定义虚拟目录及虚拟目录路径,其中虚拟目录名称用于URL访问的路径别名,可以和虚拟目录名称不同
#<Directory/>节点用于定义目录的访问权限等
#
#Alias 虚拟目录名称 虚拟目录路径
#<Directory 虚拟目录路径>
# Options Indexes FollowSymLinks
# AllowOverride All
# Order allow,deny
# Allow from all
#</Directory> #下面是具体的示例,/DemoSite是目录别名 "D:/Code/WebSite"是虚拟目录的实际路径
Alias /DemoSite "D:/Code/WebSite" <Directory "D:/Code/WebSite">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>


重启Apache服务后,在浏览器输入http://localhost:8080/DemoSite就可以正常访问了
这里需要注意下目录尽量使用"/",而不是使用"\",原因就是"\"代表转义符有些情况下会导致莫名奇妙的错误,下面附上完整的<IfModule alias_module>节点以供参考

<IfModule alias_module>
#
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo http://localhost/bar #
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a <Directory> section to allow access to
# the filesystem path. #
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
#
ScriptAlias /cgi-bin/ "D:/Program Files/Apache2.2/cgi-bin/" Alias /DemoSite "D:/Code/WebSite" <Directory "D:/Code/WebSite">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</IfModule>

多主机头绑定
(就是在一个端口上绑定多个域名,然后每个域名可以指向不同的目录进行访问,主机头是IIS里面的说法),打开httpd.conf文件,在文件最后添加如下内容


#多主机头配置无需放在特定的节点下面,一般直接在配置文件底部添加即可
#NameVirtualHost addr[:port] 为一个基于域名的虚拟主机指定一个IP地址(和端口)
#声明主机头必须加这条指令,否者主机头配置不会生效
#VirtualHost节点下面ServerName就是要绑定的域名,DocumentRoot表示此域名指向的目录
#本机测试的话请在hosts中进行域名绑定如 127.0.0.1 www.mysite1.com
NameVirtualHost *:8080
<VirtualHost *:8080>
ServerName www.mysite1.com
DocumentRoot "D:\Program Files\Apache2.2\htdocs"
</VirtualHost> <VirtualHost *:8080>
ServerName www.mysite2.com
DocumentRoot "D:\Code\MySite"
</VirtualHost>


配置好后,重启apache服务,浏览器输入www.mysite1.com:8080,就会自动定向到D:\Program Files\Apache2.2\htdocs站点了
输入www.mysite2.com:8080就会自动定向到D:\Code\MySite站点,如此就可以实现在一个服务器上同时运行多个站点
Apache配置虚拟目录和多主机头的更多相关文章
- Apache配置虚拟目录,以及各种操作
apache配置虚拟目录: 打开并创建虚拟目录的步骤如下: # Virtual hosts # Include conf/extra/httpd-vhosts.conf 去掉conf/http.con ...
- Apache配置虚拟目录+Zend Studio访问
1 概述 Apache配置虚拟目录,然后可以通过Zend Studio的工程去访问,只需要修改Apache的httpd.conf文件. 2 修改httpd.conf 找到Apache安装目录下的htt ...
- PHP学习笔记:APACHE配置虚拟目录、一个站点使用多域名配置方式
我用的是xmapp lite2016的集成包,配置虚拟目录教程如下: 找到httpd-vhosts.conf这个文件,这个文件一般是在xampp\apache\conf\extra这个路径下面,找不到 ...
- apache配置--虚拟目录
apache在httpd-vhosts.conf中 配置二级域名或者泛域名: <VirtualHost *:80> ServerAdmin 846606478@qq.com D ...
- apache 配置虚拟目录
#注释掉apache默认的网站目录地址 #DocumentRoot "c:/Rrogram Files/Apache/htdocs" #配置一个虚拟目录 <ifModule ...
- apache配置虚拟目录
#虚拟目录配置 <IfModule dir_module> DirectoryIndex index.html index.htm index.php Alias /htdocs &quo ...
- windows下面apache配置虚拟目录(测试使用,发布网站不建议目录访问)
windows下面是这样简单设置 1 Apache虚拟目录: 针对某一目录可以这么设置: Alias /aidd2008 "D:/php/web/aidd2008" <Dir ...
- apache的虚拟目录的配置
第一步:在httpd.conf底部添加以下代码.表示添加虚拟目录 1 <IfModule dir_module> #direcotory相当于是欢迎页面 DirectoryIndex in ...
- apache 配置网站目录,虚拟目录,新端口
1 配置网站目录,以ubuntu为例 1)打开apache的默认配置文件夹:cd /etc/apache2/sites-available 2)打开配置文件,本机为sudo vi 000-defau ...
随机推荐
- 跨域解决方案CORS使用方法
CORS(Cross-Origin Resource Sharing), 目前CORS还处于w3c的草案,它定义了跨域访问时服务器和客户端之间如何通信.他的原理是通过定义HTTP头部的信息,来让客户端 ...
- GHOST中DISK TO DISK 和DISK FROM to image的区别
Ghost的Disk菜单下的子菜单项可以实现硬盘到硬盘的直接对拷(Disk-To Disk)、硬盘到镜像文件(Disk-To Image)、从镜像文件还原硬盘内容(Disk-From Image)。 ...
- 【BZOJ 1412】[ZJOI2009]狼和羊的故事
Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! O ...
- 微软职位内部推荐-Principal Architect for Windows Security
微软近期Open的职位: Location: China, BeijingDivision: Operations System Group Engineering Group OverviewOSG ...
- TOPAPI 消息通知机制
接收用户订阅消息 public class UserSubMain { public static void main(String[] args ) throws ApiException { St ...
- 关于安装Android Studio的一些问题的解决方法
问题1:每次Fetching android sdk component information 这是在检查你的 Android SDK .有人会在这里卡上很长时间,很大的原因就是:网络连接有问题.可 ...
- BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告
这个题感觉比较简单,但却比较容易想残.. 我不会用树状数组求这个原排列,于是我只好用线段树...毕竟 Gromah 果弱马. 我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这 ...
- properties配置文件中文乱码解决方法
方法1 properties文件的格式一般为: ROOT=http://localhost:8080/BNCAR2/ ROOTPATH=E:/ws2/BNCAR2/rel/ MALL_PARTS_ ...
- PHP 性能分析第三篇: 性能调优实战
注意:本文是我们的 PHP 性能分析系列的第三篇,点此阅读 PHP 性能分析第一篇: XHProf & XHGui 介绍 ,或 PHP 性能分析第二篇: 深入研究 XHGui. 在本系列的 ...
- 内核request_mem_region 和 ioremap的理解
request_mem_region仅仅是linux对IO内存的管理,意思指这块内存我已经占用了,别人就不要动了,也不能被swap出去.使用这些寄存器时,可以不调用request_mem_region ...