wamp设置多站点与外网访问

原文地址 : https://www.jianshu.com/p/732b249a1398

 

 

 

1. 配置 wamp 局域网访问


2017.3.15 更新

这段时间把 wamp 更新到 3.0.6 版本了,发现用下面的方法设置局域网访问已经过时了。另请参考 WampServer3.0.4 允许外网访问配置教程


(1)需要修改的文件:httpd.conf
(2)文件所在路径:"D:\wamp\bin\apache\apache2.4.9\conf\httpd.conf"(运行 wamp 之后,点击任务栏的图标,在 Apache 先也能找到这个文件的对应选项)
(3)修改哪里? 打开httpd.conf之后,搜索“Require local”(你会发现只有一个搜索结果,这就对了),把它改为 “Require all granted”。如下:

Require local 表示“要求本地主机,即只有本地主机才能访问本服务器”,Require all granted 表示“要求所有经过授权的主机,即所有经过授权的主机(不一定是本地主机)都可以访问本服务器”

#   onlineoffline tag - don't remove
    # Require local
    Require all granted

(4)最后,重新启动服务即可。

2. 自定义 wamp 根目录

(1)需要修改的文件:httpd.conf
(2)文件所在路径:"D:\wamp\bin\apache\apache2.4.9\conf\httpd.conf"(运行 wamp 之后,点击任务栏的图标,在 Apache 先也能找到这个文件的对应选项)
(3)修改哪里? 打开httpd.conf之后,

① 查找“documentroot”可以定位到以下这一段代码:

原来的配置为:

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:/wamp/www/"

修改为:

DocumentRoot "D:/wwws"

② 查找“Require local”可以定位到以下这一段代码:

原来的配置为:

<Directory "D:/wamp/www/">
    #
    # 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.4/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:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    # Require local
    Require all granted
</Directory>

修改为:

<Directory "D:/wwws">

(4)追求完美,还需要修改任务栏中 wamp 图标中的根目录链接。

① 需要修改的文件:wampmanager.ini
② 文件路径:"D:\wamp\wampmanager.ini"
③ 如何修改?打开wampmanager.ini 之后,
查找 [Menu.Left] ,
原来的配置为:

Type: item; Caption: "www directory"; Action: shellexecute; FileName: "D:/wamp/www"; Glyph: 2

修改为:

Type: item; Caption: "wwws directory"; Action: shellexecute; FileName: "D:/wwws"; Glyph: 2

① 需要修改的文件:wampmanager.tpl
② 文件路径:"D:\wamp\wampmanager.tpl"
③ 如何修改?打开wampmanager.tpl之后,
查找 [Menu.Left] ,
原来的配置为:

Type: item; Caption: "${w_wwwDirectory}"; Action: shellexecute; FileName: "${wwwDir}"; Glyph: 2

修改为:

Type: item; Caption: "wwws directory"; Action: shellexecute; FileName: "D:/wwws"; Glyph: 2

(5)最后,退出 wamp,在重新打开。

3. wamp 多站点配置(前提是自定义了根目录)

注:开启了多站点功能之后,依旧可以使用局域网访问功能,但是必须将需要局域网访问的那个站点放置到httpd-vhosts.conf 文件的最前面。

(1)需要修改的文件:httpd-vhosts.conf
(2)文件所在路径:"D:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf"
(3)如何修改?文件里面本身就带有示例,我们只需把示例复制粘贴一遍,然后修改一下即可。例如:

httpd-vhosts.conf 文件自带的示例是这样子的:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

我们复制粘贴一遍,修改为酱紫:

<VirtualHost *:80>
    DocumentRoot "D:/wwws/dev01"
    ServerName dev01.com
</VirtualHost>

附以此文件中的描述:
If you want to maintain multiple domains/hostnames on yourmachine 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.
译:如果你想在你的机器上包含多个域名或主机,你可以为它们设置虚拟主机容器。大部分配置使用只基于主机名称的虚拟主机,因此不需要为服务器的 IP 地址的问题而担心。这(指主机名称)通过下面指令中的 * 来表示(具体请看上面的龄段代码中的 * ,大家应该能理解其含义了吧)。

(4)httpd-vhosts.conf 是作为一个扩展文件而存在的,默认情况下是不加载的,所以我们还需要让 Apache 加载这个文件。做法如下:
① 需要修改的文件:httpd.conf
② 文件路径:"D:\wamp\bin\apache\apache2.4.9\conf\httpd.conf"(运行 wamp 之后,点击任务栏的图标,在 Apache 先也能找到这个文件的对应选项)
③ 修改哪里?查找“httpd-vhosts.conf”,把“#Include conf/extra/httpd-vhosts.conf”前面的 # 去掉即可()。
原来是这样子的(#是注释):

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

把 # 去掉即可把 目标扩展文件 包含进来:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

(5)重新启动服务,至此,wamp 的配置已经完成。

(6)但要正常访问前面所设置的域名 dev01.com,还需要设置电脑的 hosts 文件。做法如下:

① 需要修改的文件:hosts
② 文件路径:"C:\Windows\System32\drivers\etc\hosts"
③ 如何修改?(我碰到的情况是 win 10 不允许直接修改 hosts 文件。想到的可行的办法是:把 hossts 文件复制到桌面,然后修改,最后粘贴会原来的文件夹并覆盖掉原来的文件)

加入以下内容:(众所周知,127.0.0.1指向 localhost;这段内容的意思就是:域名dev01.com将会在127.0.0.1之下解析)

127.0.0.1       dev01.com

All over.Thanks

posted @ 2018-01-04 23:39  免费用户  阅读(637)  评论(0编辑  收藏  举报