web伺服器是否每個伺服器只包含一個網站?

當您第一次開始學習域名、IP地址、web伺服器和網站如何相互配合和協同工作時,有時會有點困惑或不知所措。這一切是怎麼安排得如此順利的?今天的超級使用者問答帖子回答了一位好奇的讀者的問題。...

web伺服器是否每個伺服器只包含一個網站?

當您第一次開始學習域名、IP地址、web伺服器和網站如何相互配合和協同工作時,有時會有點困惑或不知所措。這一切是怎麼安排得如此順利的?今天的超級使用者問答帖子回答了一位好奇的讀者的問題。

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。

照片由Ro**arie Voegtli(Flickr)提供。

問題

超級使用者閱讀器user3407319想知道web伺服器是否每個網站只包含一個:

Based on what I understand about DNS and linking a domain name with the IP address of the web server a website is stored on, does that mean each web server can only hold one website? If web servers do hold more than one website, then how does it all get resolved so that I can access the website I want without any problems or mix ups?

web伺服器是每個只容納一個網站,還是容納更多的網站?

答案

超級使用者貢獻者Bob為我們提供了答案:

Basically, the browser includes the domain name in the HTTP request so the web server knows which domain was requested and can respond accordingly.

HTTP Requests

Here is how your typical HTTP request happens:

1. The user provides a URL, in the form http://host:port/path.

2. The browser extracts the host (domain) part of the URL and translates it into an IP address (if necessary) in a process known as name resolution. This translation can occur via DNS, but it does not have to (for example, the local hosts file on common operating systems bypasses DNS).

3. The browser opens a TCP connection to the specified port, or defaults to port 80 on that IP address.

4. The browser sends an HTTP request. For HTTP/1.1, it looks like this:

007Ys3FFgy1gpdcultw8qj30hd01ldfo

The host header is standard and required in HTTP/1.1. It was not specified in the HTTP/1.0 spec, but some servers support it anyway.

From here, the web server has several pieces of information that it can use to decide what the resp***e should be. Note that it is possible for a single web server to be bound to multiple IP addresses.

  • The requested IP address, from the TCP socket (the IP address of the client is also available, but this is rarely used, and sometimes for blocking/filtering)
  • The requested port, from the TCP socket
  • The requested host name, as specified in the host header by the browser in the HTTP request
  • The requested path
  • Any other headers (cookies, etc.)

As you seem to have noticed, the most common shared hosting setup these days puts multiple websites on a single IP address:port combination, leaving just the host to differentiate between websites.

This is known as a Name-Based Virtual Host in Apache-land, while Nginx calls them Server Names in Server Blocks, and IIS prefers Virtual Server.

What About HTTPS?

HTTPS is a bit different. Everything is identical up to the establishment of the TCP connection, but after that an encrypted TLS tunnel must be established. The goal is to not leak any information about the request.

In order to verify that the web server actually owns this domain, the web server must send a certificate signed by a trusted third party. The browser will then compare this certificate with the domain it requested.

This presents a problem. How does the web server know which host/website’s certificate to send if it needs to do this before the HTTP request is received?

Traditionally, this was solved by having a dedicated IP address (or port) for every website requiring HTTPS. Obviously, this has become problematic as we are running out of IPv4 addresses.

Enter SNI (Server Name Indication). The browser now passes the host name during the TLS negotiati***, so the web server has this information early enough to send the correct certificate. On the web server side, configuration is very similar to how HTTP virtual hosts are configured.

The downside is the host name is now passed as plain text before encryption, and is essentially leaked information. This is usually c***idered an acceptable trade-off though c***idering the host name is normally exposed in a DNS query anyway.

What If You Request a Website by IP Address Only?

What the web server does when it does not know which specific host you requested depends on the web server’s implementation and configuration. Typically, there is a “default”, “catch-all”, or “fall back” website specified that will provide resp***es to all requests that do not explicitly specify a host.

This default website can be its own independent website (often showing an error message), or it could be any of the other websites on the web server depending on the preferences of the web server admin.


有什麼要補充的解釋嗎?在評論中發出聲音。想從其他精通技術的Stack Exchange使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。

  • 發表於 2021-04-09 11:57
  • 閱讀 ( 49 )
  • 分類:網際網路

你可能感興趣的文章

您需要了解的有關內容管理系統的所有資訊

...示。但另一方面,有一些軟體正在努力為你服務。大量的伺服器正在利用內容管理系統來建立和服務您喜愛的內容。 ...

  • 發佈於 2021-03-13 12:08
  • 閲讀 ( 49 )

使用xampp在windows上免費託管和編輯網站

...似乎典型的web開發培訓場地也是最昂貴的:購買域、主機伺服器、WordPress帳戶、主題等。但是如果你不是一個小企業主或試圖建立一個品牌呢?如果你只是想學習網路開發呢? ...

  • 發佈於 2021-03-14 07:36
  • 閲讀 ( 41 )

放棄cms並考慮靜態站點生成器的7個原因

...的第一個頁面就是這樣的:有人編寫為HTML檔案並上傳到伺服器的單個頁面。現代的CMS(contentmanagementsystem)將內容呈現為一個頁面,而實際上它將標記、資料庫內容和實時計算混為一談。它們是幫助使用者建立內容、儲存內容,...

  • 發佈於 2021-03-14 15:10
  • 閲讀 ( 53 )

儲存和備份網站,以便使用httrack離線閱讀

...您可以將整個網頁從internet複製到本地目錄,包括儲存在伺服器上的完整HTML程式碼、影象和其他檔案。一旦將網站映象到計算機上,就可以在瀏覽器中啟動它並在頁面中導航,就像檢視原始版本一樣。您還可以更新下載的頁面以...

  • 發佈於 2021-03-15 16:31
  • 閲讀 ( 47 )

廣告商如何使用網路信標在網上和電子郵件中跟蹤你

...頁並且該網頁包含一個web信標影象時,您的瀏覽器會向web伺服器發出一個下載該影象的請求,並且透過該請求,伺服器會記錄某些詳細資訊,如您的IP地址、日期和時間等。 ...

  • 發佈於 2021-03-16 12:10
  • 閲讀 ( 60 )

開始使用gnome epiphany web應用程式的5個原因

...你只能透過瀏覽器訪問。從技術上講,它們是執行在其他伺服器上的程式,您可以遠端訪問。 ...

  • 發佈於 2021-03-21 10:10
  • 閲讀 ( 71 )

什麼是刮網?如何從網站收集資料

...的關係不大,但越來越多的裝置將這些資訊從世界各地的伺服器傳送到我們的眼睛和大腦。 ...

  • 發佈於 2021-03-22 00:36
  • 閲讀 ( 43 )

使用靜態站點生成器快速構建網站

...頁的方法是將每個頁面**成一個檔案,然後將檔案上傳到伺服器。在當今資料庫和高階管理面板的世界中,這似乎有點過時了。但這兩種趨勢的結合導致了ssg的日益流行。 ...

  • 發佈於 2021-03-25 19:23
  • 閲讀 ( 63 )

什麼是谷歌分析,它是如何衡量的?

...以後使用。它使用JavaScript,這意味著即使從快取或代理伺服器獲取頁面,它也將收集資料。 ...

  • 發佈於 2021-03-28 03:01
  • 閲讀 ( 50 )

為什麼要使用cdn來改善網站的使用者體驗

... CDN是位於世界各地不同位置的一組伺服器。這些伺服器儲存靜態內容,如HTML、影象和影片。 ...

  • 發佈於 2021-03-29 20:18
  • 閲讀 ( 44 )
vvwc1593
vvwc1593

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦