配置本地的虛擬主機
我新建了一個項目,名Hello,位于:I:/wamp/www目錄下。 想訪問這個項目,需要在地址欄上輸入localhost/hello,但是我不想這樣,我想要在地址欄輸入local.hello.com就可以訪問到我這個項目。具體步驟,如下:
第一步、找到httpd.conf
該文件在I:/wamp/bin/apache/apache2.4.9/conf目錄下
第二步、打開httpd.conf開啟部分功能(推薦使用editplus等輕量級編輯器,不推薦記事本)
①使用快捷鍵ctrl+F搜索mod_rewrite.so ,找到如圖位置,去掉前面的#(開啟功能)
②使用快捷鍵ctrl+F搜索Include conf/extra/httpd-vhosts.conf ,找到如圖位置,去掉前面的#
記得一定要去掉#,然后保存保存(如果沒有權限修改,可以在右鍵屬性–>安全點擊編輯權限)
第三步、找到httpd-vhosts.conf
該文件在 I:/wamp/bin/apache/apache2.4.9/conf/extra目錄下
第四步、打開httpd-vhosts.conf,添加如下代碼
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "I:/wamp/www/Hello" ServerName local.hello.com ErrorLog "logs/local.hello.com-error.log" CustomLog "logs/local.hello.com-access.log" common</VirtualHost><VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "I:/wamp/www" ServerName localhost ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common</VirtualHost>主要是修改DocumentRoot和ServerNam
第五步、找到系統盤下的hosts文件
該文件在C:/Windows/System32/drivers/etc目錄下,如圖,如果沒有權限保存,把它復制出來,待會兒修改了后再粘貼到此處,并覆蓋。
第六步、打開hosts,并在末端加入以下內容
127.0.0.1 localhost127.0.0.1 local.hello.com第七步、以上操作別忘了保存保存,最后重啟apache
原文地址:http://liuyanzhao.com/624.html