XAMPP Apache 配置多端口和多域名方法

来源:互联网 发布:剑网三脸型数据萝莉 编辑:程序博客网 时间:2024/06/08 13:32

在项目中,我们经常要将域名解析到本地,也就是在本机上添加一个虚拟主机。

可能像这样(其中的端口号建议不使用系统所保留(即 1024 以下)的):

http://192.168.1.10:8080/http://192.168.1.10:8081/http://192.168.1.10:8082/

或者是

http://www.a.comhttp://www.b.com

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

XAMPP 安装路径:D:\xampp*网站根目录:D:\xampp\htdocs*APACHE 所在位置:D:\xampp\apache

配置方法
1、创建 2 个以上不同的网站目录,存放不同的网站程序,小明创建后如下:

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

2、配置 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.com127.0.0.1 www.b.com

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

Listen 80Listen 8080Listen 8081

4、如果你想实现不同端口(http://localhost:8080/、http://localhost:8081/)访问不同网站,就需要在该文件最底部添加:

多端口虚拟主机配置

<virtualhost *:8080>    ServerName localhost    DocumentRoot D:\xampp\htdocs\dedecms_test</virtualhost>
dedecms_test #<virtualhost *:8081>    ServerName localhost    DocumentRoot D:\xampp\htdocs\dedecms_test</virtualhost>

如果你想采用不同域名访问不同网站,就需要在底部添加:

多域名虚拟主机配置 #

 ServerName www.a.com    DocumentRoot D:\xampp\htdocs\dedecms_test</virtualhost># dedecms_test #<virtualhost *:80>    ServerName www.b.com    DocumentRoot D:\xampp\htdocs\discuz_test</virtualhost>

5、最重要的一步,重启 apache 服务。完毕

0 0
原创粉丝点击