整個配置涉及的文件有:(假設個人wamp安裝D盤) php
C:/Windows/System32/drivers/etc 下的 hosts文件 html
D:/wamp/bin/apache/apache2.4.9/conf/extra 下的 httpd-vhosts.conf mysql
D:/wamp/bin/apache/apache2.4.9/conf 下的 httpd.conf web
步驟: sql
1.編輯httpd.conf apache
LoadModule php5_module "d:/wamp/bin/php/php5.5.12/php5apache2_4.dll"
PHPIniDir d:/wamp/bin/php/php5.5.12
Include conf/extra/httpd-vhosts.conf
查看這三句,若是它們被#註釋了的話,去掉# (說明一下,第三句話通常註釋的,去掉註釋後就能開啓配置站點)保存。 瀏覽器
此外,還有一個地方須要設置,wamp2.5默認只容許本地訪問,咱們須要作的就是把本地改成所有均可以訪問: 服務器
查找:<Directory "D:/wamp/www/">,找到 app
<Directory "E:/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 Require all granted // 此處加上這段,表示容許全部訪問站點 # # Controls who can get stuff from this server. # # onlineoffline tag - don't remove # Require local // 註釋此處,目的是禁掉只容許本地訪問 </Directory>
2.編輯 httpd-vhosts.conf
上面那步的第三句話就是讓本文件的配置起做用 ide
咱們看到23~30行,這就是一個配置站點的範例,你能夠參照它來寫本身想要的站點信息:
<VirtualHost *:80> DocumentRoot "d:/wamp/www/demo/" // 此處表示網站代碼根目錄 ServerName www.demo1.com // 此處表示站點網址 </VirtualHost> <VirtualHost *:80> DocumentRoot "d:/wamp/www/web/" ServerName www.demo2.com </VirtualHost>
3.編輯 hosts文件
畢竟咱們的站點是在虛擬服務器上運行的,還得把咱們的服務名告訴機器
這最後一步就是告訴本主機你的站點名:
作法是在本文件最後添上
127.0.0.1 demo1.com
127.0.0.1 demo2.com
按照以上流程配置完之後,重啓wamp全部服務,在瀏覽器輸入demo1.com或demo2.com 就能訪問到本身的站點了。