wamp设置多站点与外网访问

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

 

 

 

1. 配置 wamp 局域网访问


2017.3.15 更新css

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


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

Require local 表示“要求本地主机,即只有本地主机才能访问本服务器”,Require all granted 表示“要求全部通过受权的主机,即全部通过受权的主机(不必定是本地主机)均可以访问本服务器”shell

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

(4)最后,从新启动服务便可。apache

2. 自定义 wamp 根目录

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

① 查找“documentroot”能够定位到如下这一段代码:服务器

原来的配置为:dom

# 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/" 

修改成:ide

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

相关文章
相关标签/搜索