XAMPP3.1.0中Apache2.4.3的多站点配置(vhost/virtual host)
2013-09-10 23:33
489 查看
最近想在Apache2.4.3上挂载多站点,可是怎么都不成功。我使用的是同一个IP、不同名字的方法(也叫Name-Based方法,另外一种方法叫IP-Based)。也就说本机IP都是127.0.0.1,但是访问localhost、www.a.com、www.b.com时,所指向的网站目录不同。
最终要实现的指向是:
127.0.0.1 ==> D:/xampp/htdocs/xampp
localhost ==> D:/xampp/htdocs/xampp
www.a.com ==> D:/xampp/htdocs/a
www.b.com ==> D:/xampp/htdocs/b
(有人可能会问,能不能指向“xampp/htdocs”以外的目录,比如G:/website/a。这个应该得修改httpd.conf中的DocumentRoot。可修改后,浏览127.0.0.1和localhost就不会指向xampp/htdocs/xampp了。如果不修改原有的DocumentRoot,只仅仅添加Dirctory,我试了网上各种添加方法,都没成功。可能是版本原因。所以在文章标题处特地注明了我所使用的版本。所以,为了效果好、方便,还是把站点都放在xampp/htdocs下吧。)
1.修改C:\Windows\System32\drivers\etc下的hosts文件:
2.在D:\xampp\htdocs中新建目录/a/、/a/logs/、/b/、/b/logs/
3.修改D:\xampp\apache\conf\extra下的httpd-vhost.conf:
4.保存文件,重启Apache即可。
最终要实现的指向是:
127.0.0.1 ==> D:/xampp/htdocs/xampp
localhost ==> D:/xampp/htdocs/xampp
www.a.com ==> D:/xampp/htdocs/a
www.b.com ==> D:/xampp/htdocs/b
(有人可能会问,能不能指向“xampp/htdocs”以外的目录,比如G:/website/a。这个应该得修改httpd.conf中的DocumentRoot。可修改后,浏览127.0.0.1和localhost就不会指向xampp/htdocs/xampp了。如果不修改原有的DocumentRoot,只仅仅添加Dirctory,我试了网上各种添加方法,都没成功。可能是版本原因。所以在文章标题处特地注明了我所使用的版本。所以,为了效果好、方便,还是把站点都放在xampp/htdocs下吧。)
1.修改C:\Windows\System32\drivers\etc下的hosts文件:
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. 127.0.0.1 localhost 127.0.0.1 www.a.com 127.0.0.1 www.b.com # ::1 localhost
2.在D:\xampp\htdocs中新建目录/a/、/a/logs/、/b/、/b/logs/
3.修改D:\xampp\apache\conf\extra下的httpd-vhost.conf:
# # 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 postmaster@dummy-host.localhost ##DocumentRoot "D:/xampp/htdocs/dummy-host.localhost" ##ServerName dummy-host.localhost ##ServerAlias www.dummy-host.localhost ##ErrorLog "logs/dummy-host.localhost-error.log" ##CustomLog "logs/dummy-host.localhost-access.log" combined ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin postmaster@dummy-host2.localhost ##DocumentRoot "D:/xampp/htdocs/dummy-host2.localhost" ##ServerName dummy-host2.localhost ##ServerAlias www.dummy-host2.localhost ##ErrorLog "logs/dummy-host2.localhost-error.log" ##CustomLog "logs/dummy-host2.localhost-access.log" combined ##</VirtualHost> # 挂载多站点 #配置回原localhost,不然原localhost的访问会出错 <virtualhost *:80> ServerName localhost DocumentRoot "D:/xampp/htdocs" </virtualhost> #添加站点1 <virtualhost *:80> ServerName www.a.com DocumentRoot "D:/xampp/htdocs/a/" ErrorLog "D:/xampp/htdocs/a/logs/www.a.com.log" CustomLog "D:/xampp/htdocs/a/logs/www.a.com.log" combined </virtualhost> #添加站点2 <virtualhost *:80> ServerName www.b.com DocumentRoot "D:/xampp/htdocs/b/" ErrorLog "D:/xampp/htdocs/b/logs/www.b.com.log" CustomLog "D:/xampp/htdocs/b/logs/www.b.com.log" combined </virtualhost>Apache2.4.x可不用NameVirtualHost *:80,官网也不推荐使用。使用了在error.log中反而会出现警告“AH00548: NameVirtualHost has no effect and will be removed in the next release D:/xampp/apache/conf/extra/httpd-vhosts.conf:46”。
4.保存文件,重启Apache即可。
相关文章推荐
- xampp/apache多站点配置
- XAMPP集成环境下apache配置多端口多站点访问
- Linux-CentOS XAMPP Apache 防盗链模块mod_auth_token的安装配置
- windows下利用apache配置WEB站点(转)
- 在本地Apache服务器配置虚拟主机站点
- APACHE站点域名文件夹指向配置
- apache配置多个站点
- apache 配置不同的端口访问不同的站点
- window apache 多站点配置
- Apache配置同一端口(非80)多站点
- Apache配置多站点(转载)
- mac 下 xampp 多域名 多站点 多虚拟主机 配置
- apache中使用mod_gnutls模块实现多个SSL站点配置(多个HTTPS协议的虚拟主机)
- Win2003完美配置Apache+IIS+Tomcat多站点
- apache入门基本知识,配置多个站点
- 使用 Apache Web 配置多个站点
- Ubuntu下Apache多站点虚拟主机配置
- apache 多站点配置
- apache 配置虚拟域名默认站点问题
- Claros intouch 2.1 + Apache James 2.3.2 +Xampp 1.8---Claros intouch2.1配置