您的位置:首页 > 运维架构 > Apache

xampp3.2 apache 配置多端口 多域名

2014-09-03 14:46 134 查看
我们本机采用 XAMPP 搭建,底端采用的 APACHE,本文配置方法不仅仅适用于 XAMPP,还适用于任意已安装 APACHE 的机子。我们一起来动手配置下:

XAMPP 安装路径:D:\xampp

*网站根目录:D:\xampp\htdocs 即httpd.conf 下的配置的DocumentRoot目录

*APACHE 所在位置:D:\xampp\apache

配置方法

1、创建 2 个以上不同的网站目录,存放不同的网站程序,小明创建后如下:
(1)D:\xampp\htdocs\dedecms_test(存放织梦程序)

(2)D:\xampp\htdocs\discuz_test(存放 DISCUZ 论坛程序)

注意这两个目录一定要在网站根目录下 即httpd.conf 下的配置的DocumentRoot目录

2、记事本编辑 D:\xampp\apache\conf\httpd.conf,在顶部添加需要被监听的端口:8080、8081,保留默认监听的 80 端口

Listen 80

Listen 8080

Listen 8081

3、如果你想实现不同端口(http://localhost:8080/、http://localhost:8081/)访问不同网站,就需要在httpd-vhosts.conf添加以下:
注:要查看httpd.conf是否开通

# Virtual hosts

Include conf/extra/httpd-vhosts.conf #此句前面无#号

# 多端口虚拟主机配置 #

<virtualhost *:8080>

ServerName localhost

DocumentRoot D:/xampp/htdocs/dedecms_test

</virtualhost>

# dedecms_test #

<virtualhost *:8081>

ServerName localhost

DocumentRoot D:/xampp/htdocs/dedecms_test

</virtualhost>

4、如果你想采用不同域名访问不同网站,就需要配置 2 个域名(可以任意):www.a.com、www.b.com,他们都指向了 127.0.0.1(本机)

(1)记事本打开 C:\Windows\System32\drivers\etc\hosts

(2)在该文件底部添加以下代码并保存:

127.0.0.1 www.a.com

127.0.0.1 www.b.com

httpd-vhosts.conf 下配置

# 多域名虚拟主机配置

<virtualhost *:8080>

ServerName www.a.com

DocumentRoot D:/xampp/htdocs/dedecms_test

</virtualhost>

# dedecms_test #

<virtualhost *:8081>

ServerName www.b.com

DocumentRoot D:/xampp/htdocs/dedecms_test

</virtualhost>

5、最重要的一步,重启 apache 服务。浏览器输入:http://localhost:8080/、http://localhost:8081/、http://www.a.com/、http://www.b.com 试试哇~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: