apache虛擬主機
伊谢尔伦
伊谢尔伦 2017-05-16 16:57:58
0
3
780

最近在研究虛擬主機,然後我配置了兩個虛擬主機,如下

#其中一個的ServerName設定為127.0.0.1 。然後再C盤的hosts檔案裡面增加

#那麼問題來了。
我在瀏覽器直接輸入www.abc.com時候會訪問到E:/wamp/crm這個項目,為什麼呢?在hosts裡面www.abc.com不是對應127.0.0.1嗎,不是應該去E:/wamp/wamp/www這個專案嗎?然後我在瀏覽器直接輸入127.0.0.1的時候訪問的是E:/wamp/wamp/www這個專案?就是這裡搞不懂。 。 。 。請大神搭救搭救。 。 。 。 。 。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回覆(3)
洪涛

官方文件在此:An In-Depth Discussion of Virtual Host Matching

你這個屬於“Name-based vhost”,就看這段好了:

If there are multiple VirtualHost directives listing the IP address
and port combination that was determined to be the best match, the
"list" in the remaining steps ers to the list of vhosts that, the the configuration file.

我來簡單翻譯,在vhost IP和端口吻合的情況下(就是你這裡的*:80),apache會根據vhost配置文件中vhost的先後順序依次進行匹配.

If the connection is using SSL, the server supports Server Name

Indication, and the SSL client handshake includes the TLS extension
with the requested hostname, then that hostname is extension
with the requested hostname, then that hostname is headused lowd 它non-SSL connection.
Otherwise, the first name-based vhost whose address matched is used
for SSL connections. This is significant because the vhost determines
which certate the server will ificate the conn.
如果是SSL連接,會根據TLS握手資訊裡面的SNI尋找主機名稱。如果不支援SNI,就符合第一個IP和連接埠(這裡指的還是 *:80)吻合的vhost.

If the request contains a Host: header field, the list is searched for

the first vhost with a matching ServerName or ServerAlias, and the
request is served from that vhost. A Host: Alias, and the

request is served from that vhost. A Host: Alias, and the
request 是but Apache always ignores it and matches against the real
port to which the client sent the request.

如果HTTP頭部有Host訊息,則符合第一個和
吻合的虛擬主機。有的時候Host會包含連接埠訊息,Apache不會鳥這個埠。

ServerName或者ServerAliasThe first vhost in the config file with the specified IP address has the highest priority and catches any request to an unknown server name, or a request without a Host: header field (such as a HTTP/1.0 request).

如果都沒匹配上,扔給第一個IP端口(指的還是你的那個*:80)吻合的vhost

你造訪的abc.com是第一個crm那個麼?不是, 是127.0.0.1麼(只有網址列直接輸入127.0.0.1才算)? 不是,那就走預設的,也就是第一個crm的配置。

过去多啦不再A梦

個人感覺serverName沒啥用,所以你這個按優先適配原則,按80埠就直接是第一條規則。你要真想掛倆站點,用埠號區分就好了~
另外也可以看看文件。中文文件推薦譯者:金步國的。

大家讲道理

網域是用來解析為IP的,所以兩個都是127.0.0.1
而你的兩個埠同樣是80,只能存取第一個了

你把下面的改為8080,用8080埠訪問第二個

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!