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

来源:互联网 发布:mac商店英文改中文版 编辑:程序博客网 时间:2024/06/08 10:02

src:http://jingyan.baidu.com/article/08b6a591f294fe14a809229b.html

我们在工作中经常遇到同时调试多个网站的情况,那么如何配置呢?就像平时访问网站一样,网站 a.com 与网站 b.com 
截然不同。这都是常见现象,如果在局域网中要访问另外一台电脑上的多个网站,就需要使用 http://192.168.1.10/ 形式访问,而不是 
http://localhost/,http 协议默认端口号是 
80,如果我们可以设定不同的端口号,让服务器“监听器”去寻找不同的服务,岂不是更好?

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

http://192.168.1.10:8080/

http://192.168.1.10:8081/

http://192.168.1.10:8082/

我们本机采用 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.com

127.0.0.1 www.b.com

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

Listen 80

Listen 8080

Listen 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>

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

# 多域名虚拟主机配置 #<virtualhost *:80>

    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 服务。浏览器输入:http://localhost:8080/、http://localhost:8081/、http://www.a.com/、http://www.b.com 试试哇~

DedeCMS:www.a.com

Discuz:www.b.com

原作者:小明
注解:设置不同的网站目录后,别忘了为网站目录以以下的方法给目录分配权限:
<Directory "C:/Apache22/htdocs/www2">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks


    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All


    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all


</Directory>

0 0
原创粉丝点击