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
  • 阅读 ( 235 )
  • 分类:互联网

你可能感兴趣的文章

什么是cgi脚本,它们如何改进网站?

CGI代表公共网关接口。它是web服务器执行程序并为web浏览器生成输出的标准协议。该程序被称为CGI程序(或CGI脚本)。当用户的web浏览器请求特定的URL时,它代表web服务器执行以产生输出。 ...

  • 发布于 2021-03-13 08:17
  • 阅读 ( 246 )

您需要了解的有关内容管理系统的所有信息

...示。但另一方面,有一些软件正在努力为你服务。大量的服务器正在利用内容管理系统来创建和服务您喜爱的内容。 ...

  • 发布于 2021-03-13 12:08
  • 阅读 ( 204 )

使用xampp在windows上免费托管和编辑网站

...似乎典型的web开发培训场地也是最昂贵的:购买域、主机服务器、WordPress帐户、主题等。但是如果你不是一个小企业主或试图建立一个品牌呢?如果你只是想学习网络开发呢? ...

  • 发布于 2021-03-14 07:36
  • 阅读 ( 237 )

放弃cms并考虑静态站点生成器的7个原因

...的第一个页面就是这样的:有人编写为HTML文件并上传到服务器的单个页面。现代的CMS(contentmanagementsystem)将内容呈现为一个页面,而实际上它将标记、数据库内容和实时计算混为一谈。它们是帮助用户创建内容、存储内容,然...

  • 发布于 2021-03-14 15:10
  • 阅读 ( 262 )

广告商如何使用网络信标在网上和电子邮件中跟踪你

...页并且该网页包含一个web信标图像时,您的浏览器会向web服务器发出一个下载该图像的请求,并且通过该请求,服务器会记录某些详细信息,如您的IP地址、日期和时间等。 ...

  • 发布于 2021-03-16 12:10
  • 阅读 ( 443 )

什么是刮网?如何从网站收集数据

...的关系不大,但越来越多的设备将这些信息从世界各地的服务器传送到我们的眼睛和大脑。 ...

  • 发布于 2021-03-22 00:36
  • 阅读 ( 214 )

使用静态站点生成器快速构建网站

...页的方法是将每个页面**成一个文件,然后将文件上传到服务器。在当今数据库和高级管理面板的世界中,这似乎有点过时了。但这两种趋势的结合导致了ssg的日益流行。 ...

  • 发布于 2021-03-25 19:23
  • 阅读 ( 306 )

如何解决internet连接问题

...ingtl80.cn网站. 此命令将多个数据包发送到指定的地址。web服务器对它接收到的每个数据包作出响应。在下面的命令中,我们可以看到一切都正常工作-有0%的数据包丢失,每个数据包所用的时间相当低。 如果您看到数据包丢失(...

  • 发布于 2021-04-08 02:59
  • 阅读 ( 146 )

如何优化mozilla firefox以获得最大的隐私

...的功能。默认情况下,Firefox会联系Mozilla、Yahoo和Google的服务器。我们不建议您禁用所有这些功能,因为它们确实有用。但我们会解释各种选择,这样你就可以做出明智的决定。 如果您只想私下浏览而不在自己的电脑上留下曲目...

  • 发布于 2021-04-08 03:08
  • 阅读 ( 210 )

如何在mac上配置代理服务器

当您在Mac上配置代理服务器时,应用程序将通过代理服务器发送其网络流量,然后再前往其目的地。您的雇主可能要求您绕过防火墙,或者您可能希望使用代理绕过地理阻止并访问您所在国家不可用的网站。 相关:如何在Firefox...

  • 发布于 2021-04-08 07:40
  • 阅读 ( 187 )
vvwc1593
vvwc1593

0 篇文章

相关推荐