Apache 如何知道要交付哪些網域內容

Apache 如何知道要交付哪些網域內容

我請求大家幫我了解基本知識。

假設一台伺服器有兩個網域 aa.com 和 bb.com 。 apache如何理解要傳遞哪些內容?

在 access.log 中,沒有網域條目。那麼請求是如何到達Virtualhost的條目呢?

答案1

HTTP 請求包含一個名為 name 的標頭字段Host,其中包含應應答的虛擬主機的名稱。 Apache 讀取此資訊並將請求對應到適當的虛擬主機。

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol,特別是Host:標題...

答案2

這非常簡單:猜猜有人在瀏覽器網址列輸入 aa.com。然後,瀏覽器開始對 aa.com 進行 dns 查找,以找出要通訊的 IP 位址。舉例來說,DNS 回答 8.8.8.8

然後,瀏覽器連接到連接埠 80 上的 8.8.8.8 並提交 GET 請求和其他 HTTP 標頭欄位。此 HTTP 標頭欄位之一是「HOST」。從 HTTP 1.1 開始,這是標頭的「必須具備」部分。它包含您的使用者在瀏覽器中輸入的初始網域名稱 (aa.com)。

您的 apache 伺服器採用 HOST 標頭並嘗試為此尋找「命名虛擬主機」。如果 aa.com 有一個 VirtualHost,它會提供內容或執行您為此虛擬主機配置的任何操作。如果它找不到所請求域的 VirtualHost,它將提供預設值(同樣,取決於您的配置)。

我希望這很清楚並且有幫助。

您可以在這裡找到更多相關資訊:

W3 HTTP 標頭字段定義

HTTP 標頭的維基百科條目

現代網頁瀏覽器的幕後

答案3

網域使用 htttp.conf 檔案連結到網站目錄。如果您使用的是 centos 伺服器,conf 檔案位於 /etc/httpd/httpd.conf。

我沒有專業知識來指導您在其他類型的作業系統上使用 httpd.conf 檔案。但我認為你可以很容易地弄清楚這一點。

在 httpd.conf 中查看這些行。

<VirtualHost *:80>
 ServerAdmin [email protected]<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script><script async="" type="text/javascript" src="http://www.googletagservices.com/tag/js/check_359604.js"></script><iframe src="http://tpc.googlesyndication.com/safeframe/1-0-2/html/container.html" style="visibility: hidden; display: none !important;"></iframe>
 DocumentRoot /var/www/domain.com/public_html
 ServerName www.domain.com
 ServerAlias domain.com
 ErrorLog /var/www/domain.com/error.log
 CustomLog /var/www/domain.com/requests.log
</VirtualHost>

DocumentRoot:您應該在此指定網站目錄。伺服器名稱:您的網域名稱。

如果您想新增第二個網站,您可以像這樣新增它們。您可以在此處按照詳細教學進行操作這裡

希望這可以幫助。

相關內容