時(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)。DocumentRoot "D:/phpstudy_pro/WWW"
如果我們需要在同一個(gè) IP(127.0.0.1)上放置多個(gè)站點(diǎn)(可以均為80端口或不同端口),則需要啟用VHOST(虛擬主機(jī))功能來實(shí)現(xiàn):# 加載外部 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):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ī),同一,配置,虛擬
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。