該默認(rèn)站點(diǎn)的目錄由 httd.conf 文件內(nèi) DocumentRoot 行所定義:

DocumentR" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運(yùn)營 > Apache 在同一個(gè)IP上配置多臺(tái)虛擬主機(jī)(多站點(diǎn)),監(jiān)聽多個(gè)端口

Apache 在同一個(gè)IP上配置多臺(tái)虛擬主機(jī)(多站點(diǎn)),監(jiān)聽多個(gè)端口

時(shí)間:2023-07-14 07:21:01 | 來源:網(wǎng)站運(yùn)營

時(shí)間:2023-07-14 07:21:01 來源:網(wǎng)站運(yùn)營

Apache 在同一個(gè)IP上配置多臺(tái)虛擬主機(jī)(多站點(diǎn)),監(jiān)聽多個(gè)端口:一鍵安裝PHPStudy后,啟動(dòng)Apache,即可通過 http://127.0.0.1/ 訪問默認(rèn)配置的站點(diǎn)。

該默認(rèn)站點(diǎn)的目錄由 httd.conf 文件內(nèi) DocumentRoot 行所定義:

DocumentRoot "D:/phpstudy_pro/WWW"如果我們需要在同一個(gè) IP(127.0.0.1)上放置多個(gè)站點(diǎn)(可以均為80端口或不同端口),則需要啟用VHOST(虛擬主機(jī))功能來實(shí)現(xiàn):

1、配置 httd.conf 啟用VHOST:

# 加載外部 conf/vhosts/vhosts.conf 配置文件Include conf/vhosts/vhosts.conf#同時(shí)監(jiān)聽 80 8080 端口Listen 127.0.0.1:80Listen 127.0.0.1:8080#加載 vhost_alias_module 模塊LoadModule vhost_alias_module modules/mod_vhost_alias.so# 定義 SRVROOT 變量Define SRVROOT "D:/phpstudy_pro/Extensions/Apache2.4.39"#以上內(nèi)容均可在 httd.conf 文件內(nèi)搜索相關(guān)關(guān)鍵詞,在對(duì)應(yīng)位置刪掉 '#' 注釋符號(hào)或添加相應(yīng)的行實(shí)現(xiàn)2、配置 D:/phpstudy_pro/Extensions/Apache2.4.39/conf/vhosts/vhosts.conf :

<VirtualHost 127.0.0.1:80> ServerName default DocumentRoot "${SRVROOT}/htdocs" FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts" AddHandler fcgid-script .php FcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php <Directory "${SRVROOT}/htdocs"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost><VirtualHost 127.0.0.1:80> ServerName www.example.com ServerAlias www.example.com DocumentRoot "${SRVROOT}/htdocs/example" <Directory "${SRVROOT}/htdocs/example"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost><VirtualHost 127.0.0.1:8080> ServerName example02.com ServerAlias www.example02.com DocumentRoot "${SRVROOT}/htdocs/example02" <Directory "${SRVROOT}/htdocs/example02"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost>3、設(shè)置本機(jī) C:/Windows/System32/drivers/etc/hosts 文件:

# 添加如下兩行127.0.0.1 www.example.com127.0.0.1 www.example02.com如果兩個(gè)虛擬主機(jī)需要共用 80 端口,則需要像上面一樣,修改 Hosts 文件,通過在地址欄輸入不同的域名訪問不同的站點(diǎn):

1)在地址欄輸入 http://127.0.0.1/ 則顯示的是默認(rèn) (default) 站點(diǎn):

D:/phpstudy_pro/Extensions/Apache2.4.39/htdocs/index.html 的內(nèi)容:

Hello Default VHOST! (HTML文件內(nèi)容略)

2)在地址欄輸入 http://www.example.com/ 則顯示的是 example 站點(diǎn):

D:/phpstudy_pro/Extensions/Apache2.4.39/htdocs/example/index.html 的內(nèi)容:

Hello Example VHOST! (HTML文件內(nèi)容略)

3)在地址欄輸入 http://www.example02.com:8080/ 則顯示的是 example02 站點(diǎn):

D:/phpstudy_pro/Extensions/Apache2.4.39/htdocs/example02/index.html 的內(nèi)容:

Hello Example 02 VHOST! (HTML文件內(nèi)容略)

由于上述 vhosts.conf 文件配置 www.example02.com 監(jiān)聽的是8080端口,故URL中要帶上端口號(hào)( :8080 ),如果是80端口,則無需帶端口號(hào),通過 http://www.example02.com/ 即可訪問

4)如需要允許虛擬主機(jī)解析PHP腳本,需要在對(duì)應(yīng) VirtualHost 節(jié)下添加如下代碼:

FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts"AddHandler fcgid-script .phpFcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php否則虛擬主機(jī)目錄下的PHP文件會(huì)以源文件(純文本)形式返回。




關(guān)鍵詞:主機(jī),同一,配置,虛擬

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉