標籤:cal http default 127.0.0.1 設定檔 efault 就會 server 搭建
在開發的過程中,很多時候項目的部署都需要在本地進行虛擬伺服器的類比搭建,所以具體的配置流程為下,並且把自己遇到的問題跟大家分享。
1、Apache設定檔httpd.conf
找到
# Virtual hosts 這句前面的#不用去 //如果去掉了,你就會發現localhost和你設定的網域名稱路徑都會訪問不了項目!!
#Include conf/extra/httpd-vhosts.conf 去掉本行注釋 # //這個是一定一定要去掉的!!!
還有 severname localhost 前面需要加#,注釋掉。
2、Apache檔案目錄
apache/conf/extra/http-vhosts.conf
複製添加如下代碼到該檔案的最後面。
當我們配置完網域名稱訪問到項目的時候經常會出現localhost訪問不了的問題,這時候就需要加下面這部分代碼了!!
<VirtualHost _default_:80>
DocumentRoot "D:/phpStudy2/WWW" //指向正確的www檔案
ServerName localhost //保證localhost也可以訪問
</VirtualHost>
//下面的這部分代碼是非常重要的!!就是正確佈建網域名的部分
<VirtualHost *:80>
DocumentRoot "D:/phpStudy2/WWW/tpshop" //指向正確的項目位置
ServerName www.leohc.com //對應的網域名稱設定
DirectoryIndex index.html index.htm index.php
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3、 找到hosts檔案
C:\Windows\System32\drivers\etc\hosts
在最後添加如下
127.0.0.1 localhost
127.0.0.1 www.leoyi.com #設定本地訪問網址 (與上ServerName一致)
最後重啟Apache伺服器
兩個燈都顯示為綠色就說明是正常的。
Apache虛擬機器主機的搭建及相關問題解決