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

相關文章
相關標籤/搜索