1. 程式人生 > >apache下虛擬域名配置

apache下虛擬域名配置

在我們開發中通過虛擬域名來訪問一個指定的專案確實很方便,接下來教大家如何通過手動的方式去配置虛擬域名(已apache伺服器為例)

一、首頁我們得找到host檔案、windows下這個檔案在c盤中WINDOWSsystem32driversetchosts中 加入如下內容:

127.0.0.1 www.test.com
本地ip 虛擬域名

二、然後咱們得去找httpd.conf檔案、這個檔案相應位置在您web伺服器安裝的目錄下/apacheconfhttpd.conf , 找到 “Include conf/extra/httpd-vhosts.conf 如果前面有# 則需要把它刪掉

三、找到httpd-vhosts.conf檔案
<VirtualHost *:80>
ServerAdmin

[email protected]
DocumentRoot "E:/bd/ems" //這個為您的專案目錄 意思就是把虛擬域名繫結到這個目錄下
ServerName singwa.com //這個為您在host中配置 也就是虛擬域名
ErrorLog "logs/dummy-host2.example.com-error.log" // 錯誤日誌檔案
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

然後重啟伺服器訪問www.test.com就可以訪問你的專案了

備註:如果返回重啟不了,你檢視錯誤日誌,根據提示來解決。


轉自:https://www.imooc.com/article/16798