每个Web服务器仅容纳一个网站吗?

When you first start learning how domain names, IP addresses, web servers, and websites all fit and work together, it can be a little confusing or overwhelming at times. How is it all set up to work so smoothly? Today’s SuperUser Q&A post has the answers to a curious reader’s questions.

当您第一次开始学习域名,IP地址,Web服务器和网站如何相互配合并协同工作时,有时可能会有些混乱或不知所措。 如何顺利地运作? 今天的“超级用户问答”帖子回答了好奇的读者的问题。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Photo courtesy of Rosmarie Voegtli (Flickr).

图片由Rosmarie Voegtli(Flickr)提供

问题 (The Question)

SuperUser reader user3407319 wants to know if web servers only hold one website each:

超级用户阅读器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?

根据我对DNS的了解,并将域名与存储网站的Web服务器的IP地址链接起来,是否意味着每个Web服务器只能容纳一个网站? 如果网络服务器确实拥有多个网站,那么如何解决所有问题,以便我可以访问我想要的网站而不会出现任何问题或混乱?

Do web servers only hold one website each, or do they hold more?

Web服务器是每个服务器仅拥有一个网站,还是拥有更多网站?

答案 (The Answer)

SuperUser contributor Bob has the answer for us:

超级用户贡献者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请求中包含域名,因此Web服务器知道请求了哪个域并可以做出相应的响应。

HTTP Requests

HTTP请求

Here is how your typical HTTP request happens:

这是典型的HTTP请求的发生方式:

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

1.用户提供URL,格式为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).

2.浏览器在称为名称解析的过程中提取URL的主机(域)部分,并将其转换为IP地址(如有必要)。 这种转换可以通过DNS进行,但不是必须的(例如,常见操作系统上的本地主机文件会绕过DNS)。

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

3.浏览器打开到指定端口的TCP连接,或默认为该IP地址上的端口80。

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

4.浏览器发送一个HTTP请求。 对于HTTP / 1.1,它看起来像这样:

每个Web服务器仅容纳一个网站吗?

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.

主机标头是标准的,在HTTP / 1.1中是必需的。 HTTP / 1.0规范中未指定该功能,但是某些服务器仍然支持该功能。

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

从这里开始,Web服务器具有几条信息,可用于确定响应的内容。 请注意,单个Web服务器可能绑定到多个IP地址。

  • 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)

    从TCP套接字请求的IP地址(客户端的IP地址也可用,但是很少使用,有时用于阻止/过滤)
  • The requested port, from the TCP socket

    从TCP套接字请求的端口
  • The requested host name, as specified in the host header by the browser in the HTTP request

    请求的主机名,由浏览器在HTTP请求中的主机头中指定
  • The requested path

    请求的路径
  • Any other headers (cookies, etc.)

    任何其他标题(Cookie等)

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.

正如您似乎已经注意到的那样,如今最常见的共享主机设置将多个网站置于一个IP地址:端口组合中,仅由主机来区分网站。

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.

这在Apache领域被称为基于名称的虚拟主机,而Nginx在服务器块中将其称为服务器名称,而IIS则更喜欢Virtual Server

What About HTTPS?

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.

HTTPS有所不同。 直到建立TCP连接为止,所有内容都是相同的,但此后必须建立加密的TLS隧道。 目的是不泄漏有关请求的任何信息。

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.

为了验证Web服务器实际上拥有该域,Web服务器必须发送由受信任的第三方签名的证书。 然后,浏览器将将此证书与其请求的域进行比较。

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?

这带来了问题。 如果需要在接收HTTP请求之前执行此操作,Web服务器如何知道要发送哪个主机/网站的证书?

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.

传统上,这是通过为每个需要HTTPS的网站设置专用IP地址(或端口)来解决的。 显然,随着我们用尽IPv4地址,这已经成为问题。

Enter SNI (Server Name Indication). The browser now passes the host name during the TLS negotiations, 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.

输入SNI (服务器名称指示)。 现在,浏览器在TLS协商期间传递了主机名,因此Web服务器足够早地拥有此信息以发送正确的证书。 在Web服务器端,配置与HTTP虚拟主机的配置非常相似。

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

缺点是主机名现在在加密之前以纯文本形式传递,并且实质上是泄漏的信息。 尽管考虑到主机名通常还是会在DNS查询中公开,但这通常被认为是可以接受的折衷方案。

What If You Request a Website by IP Address Only?

如果仅通过IP地址请求网站怎么办?

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 responses to all requests that do not explicitly specify a host.

Web服务器在不知道您请求的特定主机时会做什么,取决于Web服务器的实现和配置。 通常,会指定一个“默认”,“全部接收”或“后备”网站,该网站将提供对未明确指定主机的所有请求的响应。

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.

该默认网站可以是其自己的独立网站(通常显示错误消息),也可以是Web服务器上的任何其他网站,具体取决于Web服务器管理员的偏好。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/260675/do-web-servers-only-hold-one-website-each/

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2021-09-09
  • 2021-12-16
  • 2021-12-06
  • 2021-12-17
  • 2021-09-13
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-05-19
  • 2021-07-29
  • 2021-11-08
  • 2021-09-29
  • 2021-12-06
相关资源
相似解决方案