Mac配置虛擬主機

2022-08-16 12:33:14 字數 2431 閱讀 1873

一、啟動apache

終端輸入:sudo apachectl start

apache的安裝目錄在:/etc/apache2/,etc預設是隱藏的。有三種方式檢視: 

1.桌面位於finder時:shift+command+g,輸入「/etc」(即finder-前往-前往資料夾的快捷鍵)

2.開啟終端:cd /etc

3.可以在terminal 輸入 "open /etc"

二、設定虛擬主機

1.在終端執行「sudo vi /etc/apache2/httpd.conf」,開啟apche的配置檔案 

2.在httpd.conf中找到「#include /private/etc/apache2/extra/httpd-vhosts.conf」,去掉前面的「#」,儲存並退出。 

3.執行「sudo apachectl restart」,重啟apache後就開啟了虛擬主機配置功能。 

4.執行「sudo vi /etc/apache2/extra/httpd-vhosts.conf」,就開啟了配置虛擬主機檔案httpd-vhost.conf,配置虛擬主機了。需要注意的是該檔案預設開啟了兩個作為例子的虛擬主機

**:

<

virtualhost

*:80

>

serveradmin [email protected]

documentroot "/usr/docs/dummy-host.example.com"

servername dummy-host.example.com

errorlog "/private/var/log/apache2/dummy-host.example.com-error_log"

customlog "/private/var/log/apache2/dummy-host.example.com-access_log" common

virtualhost

>

<

virtualhost

*:80

>

serveradmin [email protected]

documentroot "/usr/docs/dummy-host2.example.com"

servername dummy-host2.example.com

errorlog "/private/var/log/apache2/dummy-host2.example.com-error_log"

customlog "/private/var/log/apache2/dummy-host2.example.com-access_log" common

virtualhost

>

最簡單的辦法就是在它們每行前面加上#,注釋掉就好了,這樣既能參考又不導致其他問題。

5.增加如下配置,支援localhost訪問,新增虛擬主機訪問

<

virtualhost

*:80

>

documentroot "/library/webserver/documents"

servername localhost

errorlog "/private/var/log/apache2/localhost-error_log"

customlog "/private/var/log/apache2/localhost-access_log" common

virtualhost

>

<

virtualhost

*:80

>

documentroot "/library/webserver/documents"

errorlog "/private/var/log/apache2/test-error_log"

customlog "/private/var/log/apache2/test-access_log" common

<

directory

/>

options indexes followsymlinks multiviews

allowoverride none

order deny,allow

allow from all

directory

>

virtualhost

>

儲存,退出,重啟apache。

6.執行「sudo vi /etc/hosts」,開啟hosts配置檔案,加入"127.0.0.1 www.test.com",這樣就可以配置完成test虛擬主機了。

開啟瀏覽器,輸入:www.test.com

it works!

配置成功,和localhost一致!

Mac配置虛擬主機

一 啟動apache 終端輸入 sudo apachectl start apache的安裝目錄在 etc apache2 etc預設是隱藏的。有三種方式檢視 1.桌面位於finder時 shift command g,輸入 etc 即finder 前往 前往資料夾的快捷鍵 2.開啟終端 cd et...

Mac配置PHP虛擬主機

一 啟動apache 終端輸入 sudo apachectl start apache的安裝目錄在 etc apache2 etc預設是隱藏的。有三種方式檢視 1.桌面位於finder時 shift command g,輸入 etc 即finder 前往 前往資料夾的快捷鍵 2.開啟終端 cd et...

mac下配置apache虛擬主機

訪問web服務,本質上看 從協議上 是訪問某個ip的主機上的某個埠 預設是80 通常需要通過訪問不同的網域名稱或者埠實現對不同 的訪問 具體到伺服器裡就是不同目錄 這個時候就需要設定虛擬主機 virtualhost 通常分為這樣3種 基於網域名稱,基於埠,基於ip,以及它們的混合 我是自己安裝的ap...