# Web 服务器

Web 服务器是指一台计算机，或运行在其上的软件，它接受来自浏览器等客户端的 HTTP 请求，并返回包含 HTML 文档、图像和数据等 Web 内容的响应。这一术语涵盖硬件、软件，或二者协同工作：一台连接互联网、存储网站文件的机器，以及一个理解 URL 和 HTTP、并将这些内容交付给用户的 HTTP 服务器程序。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/What_is_a_web_server)</sup>

| 关键事实 | 详情 |
|---|---|
| 协议角色 | HTTP 服务器接受连接，通过发送 HTTP 响应来服务 HTTP 请求；HTTP 是一种无状态的应用层请求/响应协议<sup>[2](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 首个 Web 服务器 | CERN httpd，由蒂姆·伯纳斯-李（Tim Berners-Lee）于 1990 年圣诞节前编写，运行在 CERN 的一台 NeXT 计算机上；info.cern.ch 是首个 Web 服务器地址<sup>[3](https://timeline-upgrade.web.cern.ch/worlds-first-browsereditor-website-and-server-go-live-cern)</sup> |
| Apache 里程碑 | Apache 1.0 于 1995 年 12 月 1 日发布；据 Netcraft 调查，不到一年它便超越 NCSA httpd，成为使用最广泛的 Web 服务器<sup>[4](https://d.apache.org/ABOUT_APACHE)</sup> |
| 当今领先软件 | 在 2025 年 6 月的 Netcraft 活跃站点统计中，nginx、Cloudflare、Apache 和 Google 服务器软件分别以 18.62%、18.10%、15.54% 和 10.55% 领先<sup>[5](https://www.netcraft.com/blog/june-2025-web-server-survey)</sup> |
| 规模 | 2025 年 6 月的 Netcraft 调查收到来自 279,324,818 个域名下 1,247,534,188 个站点及 13,556,908 台面向 Web 的计算机的响应<sup>[5](https://www.netcraft.com/blog/june-2025-web-server-survey)</sup> |
| 扩展角色 | 现代服务器通常充当反向代理、内容缓存和负载均衡器；例如 nginx 可对 HTTP、HTTPS、FastCGI、uwsgi、SCGI、memcached 和 gRPC 流量进行负载均衡<sup>[6](https://nginx.org/en/docs/http/load_balancing.html)</sup> |

## Web 服务器如何处理请求

HTTP 是一种运行在可靠传输连接之上的客户端/服务器协议。客户端建立连接以发送一个或多个请求；服务器接受连接，通过发送响应来服务这些请求。同一个程序可以在某些连接上充当客户端，在另一些连接上充当服务器，因为这两个术语描述的是特定连接上的角色，而非固定类型的软件。<sup>[2](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

请求到达时，服务器解析消息，结合所标识的目标资源解释其语义，并以一条或多条响应消息作答。请求携带控制数据：方法（如 GET 或 POST）、请求目标和协议版本，以及可选的头部字段和内容。每个响应都包含一个 100 至 599 之间的三位状态码，其首位数字表示类别：1xx 信息性、2xx 成功、3xx 重定向、4xx 客户端错误、5xx 服务器错误。<sup>[2](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

在最简单的层面上，HTTP 服务器检查所请求的 URL 是否匹配现有文件。若匹配，则发回文件内容；若不匹配，则可能动态生成内容；若两者皆不可行，则返回错误，最常见的是 404 未找到。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/What_is_a_web_server)</sup> HTTP 是无状态的，这意味着每个请求的语义可以孤立地理解，服务器不得假定同一连接上的两个请求来自同一用户代理，除非该连接是安全的且专属于该代理。<sup>[2](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## 静态内容与动态内容

静态 Web 服务器是一台配有 HTTP 服务器的计算机，它按原样发送托管的文件：HTML 文档、图像、CSS 样式表、[JavaScript](https://www.edgepedia.org/zh/javascript) 文件、字体和视频。动态 Web 服务器则增加了额外软件，最常见的是应用服务器和数据库，使应用服务器在 HTTP 服务器发送内容之前更新或生成内容。像 MDN 或[维基百科](https://www.edgepedia.org/zh/wikipedia)这样的大型站点，通常由少量 HTML 模板和一个大型数据库构成，而非数千个静态文档。<sup>[1](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/What_is_a_web_server)</sup>

在动态站点上，对静态资源的请求与静态站点上的处理方式完全相同，而对动态资源的请求则被转发给服务器端代码，后者从数据库读取数据，将数据与模板结合，返回生成的 HTML。<sup>[7](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)</sup>

## 历史

首个 Web 服务器由[蒂姆·伯纳斯-李](https://www.edgepedia.org/zh/tim-berners-lee)在 CERN 编写。到 1990 年圣诞节，他已定义了 Web 的基本概念——HTML、HTTP 和 URL，并编写了首个浏览器/编辑器及服务器软件；运行在 CERN 一台 NeXT 计算机上的 info.cern.ch 是世界上首个 Web 服务器的地址。<sup>[3](https://timeline-upgrade.web.cern.ch/worlds-first-browsereditor-website-and-server-go-live-cern)</sup> 该服务器软件被称为“httpd”，在后台运行，为 [WorldWideWeb](https://www.edgepedia.org/zh/worldwideweb) 浏览器提供页面。<sup>[8](https://worldwideweb.cern.ch/history/)</sup> 1993 年 4 月 30 日，CERN 将[万维网](https://www.edgepedia.org/zh/world-wide-web)软件放入公有领域，后来又以开放许可证发布，这些举措使 Web 得以蓬勃发展。<sup>[9](https://home.cern/science/computing/the-birth-of-the-web/where-web-was-born/)</sup>

**Apache。** 截至 1995 年 2 月，Web 上使用最广泛的服务器软件是罗布·麦库尔（Rob McCool）在 NCSA 创建的公有领域 HTTP 守护进程；然而，麦库尔于 1994 年年中离开后，该工作便停止了。一小群网站管理员通过电子邮件协调各自的补丁；八位核心贡献者组成了最初的 Apache 小组。他们以 NCSA httpd 1.3 为基础，于 1995 年 4 月发布 Apache 0.6.2，并于 1995 年 12 月 1 日发布 Apache 1.0。据 Netcraft Web 服务器调查（1996 年），小组组建不到一年，Apache 便超越 NCSA httpd，成为互联网上排名第一的服务器。1999 年，Apache 小组组建了 Apache 软件基金会以支持该项目。<sup>[4](https://d.apache.org/ABOUT_APACHE)</sup>

**nginx。** nginx（“engine x”）最初由伊戈尔·瑟索耶夫（Igor Sysoev）编写，以二条款 BSD 许可证分发，是一款 HTTP Web 服务器、反向代理、内容缓存、负载均衡器以及 TCP/UDP 和邮件代理服务器，以高性能和低资源占用著称。它支持 HTTP/2 和 HTTP/3、基于名称和基于 IP 的虚拟服务器，以及长连接和流水线连接。<sup>[10](https://nginx.org/en/)</sup>

**Caddy。** Caddy 是首个自动且默认使用 HTTPS 的 Web 服务器，无需手动续期即可配置 TLS 证书；其配置中的任何主机匹配器都会触发自动 HTTPS。<sup>[11](https://github.com/caddyserver/website/blob/master/src/docs/markdown/automatic-https.md)</sup>

## 主要服务器与市场份额

Netcraft Web 服务器调查自 1995 年起每月跟踪 Web 服务器技术，涵盖 Apache、nginx、Microsoft IIS、OpenResty、LiteSpeed 及其他平台。<sup>[12](https://www.netcraft.com/resources/web-server-survey)</sup> 在 2025 年 6 月的调查中，nginx 以 18.62%（37,491,959 个站点）在活跃站点中领先，其次是 [Cloudflare](https://www.edgepedia.org/zh/cloudflare) 的 18.10%、Apache 的 15.54% 和 Google 的 10.55%。在最繁忙的一百万个站点中，Cloudflare 以 22.89% 领先，nginx 占 20.28%，Apache 占 17.68%。以面向 Web 的计算机衡量，nginx 运行在 40.96%（5,553,126 台计算机）上，Apache 占 22.52%，Microsoft 占 8.12%。<sup>[5](https://www.netcraft.com/blog/june-2025-web-server-survey)</sup>

## 反向代理与负载均衡

Web 服务器经常位于应用服务器之前。nginx 可以将流量分发到多个应用实例，以优化资源利用、最大化吞吐量、降低延迟并提供容错能力。其负载均衡方法包括轮询（默认）、最少连接（将下一个请求分配给活动连接最少的服务器）和 IP 哈希（根据客户端 IP 地址的哈希选择服务器）。其反向代理实现涵盖 HTTP、HTTPS、FastCGI、uwsgi、SCGI、memcached 和 gRPC，并包含被动式服务器健康检查。<sup>[6](https://nginx.org/en/docs/http/load_balancing.html)</sup>

## Apache httpd 的架构

[Apache HTTP Server](https://www.edgepedia.org/zh/apache-http-server) 2.0 通过多处理模块（MPM）将其模块化设计扩展到服务器最基本的功能，这些模块绑定网络端口、接受请求并调度子进程进行处理。需要可扩展性的站点选择线程化 MPM，如 `worker` 或 `event`，而需要稳定性或与旧软件兼容的站点则使用 `prefork`；每次只加载一个 MPM。在 Unix 上，当系统同时支持线程和线程安全轮询（kqueue 和 epoll）时，默认为 `event`。<sup>[13](https://d.apache.org/docs/current/mpm.html)</sup> 当前的 2.4.x 分支支持 TLS/SSL、HTTP/2、内容缓存、反向代理，以及 100 多个用于重写、代理、负载均衡和脚本编写的模块。<sup>[14](https://d.apache.org/)</sup>

## 协议演进

服务器实现相继的 HTTP 版本。HTTP/1.1 消息由起始行、头部字段和可选主体组成，请求与响应仅在起始行上有所不同。<sup>[15](https://www.ietf.org/rfc/rfc9112.pdf)</sup> HTTP/3 于 2022 年 6 月作为 RFC 9114 发布，将 HTTP 语义映射到 QUIC 传输之上；nginx 通过其 `ngx_http_v3_module` 提供 HTTP/3 支持，自 1.25.0 版本起可用。<sup>[16](https://datatracker.ietf.org/doc/rfc9114/)</sup><sup> • </sup><sup>[17](https://nginx.org/en/docs/http/ngx_http_v3_module.html?trk=public_post_comment-text)</sup>

## 安全考量

Web 服务器是拒绝服务攻击的常见目标。OWASP 关于防御资源耗尽攻击的指南包括：根据不活动情况和最终超时限制服务器端会话时间，限制文件上传大小和扩展名，限制请求总大小，防止基于输入的资源分配，以及将静态资源托管在不同域名上以减少应用程序的 HTTP 请求；缓存也能增强对带宽耗尽的抵御能力。<sup>[18](https://cheatsheetseries.owasp.org/cheatsheets/Denial_of_Service_Cheat_Sheet.html)</sup>

## References

1. [What is a web server? MDN Learn Web Development](https://developer.mozilla.org/en-US/docs/Learn_web_development/Howto/Web_mechanics/What_is_a_web_server)
2. [RFC 9110: HTTP Semantics, IETF, June 2022](https://www.rfc-editor.org/rfc/rfc9110.html)
3. [The world's first browser/editor, website and server go live at CERN, CERN timeline](https://timeline-upgrade.web.cern.ch/worlds-first-browsereditor-website-and-server-go-live-cern)
4. [About the Apache HTTP Server Project](https://d.apache.org/ABOUT_APACHE)
5. [June 2025 Web Server Survey, Netcraft](https://www.netcraft.com/blog/june-2025-web-server-survey)
6. [Using nginx as HTTP load balancer, nginx documentation](https://nginx.org/en/docs/http/load_balancing.html)
7. [Introduction to the server side, MDN Learn Web Development](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Introduction)
8. [History, WorldWideWeb NeXT Application, CERN](https://worldwideweb.cern.ch/history/)
9. [Where the web was born, CERN](https://home.cern/science/computing/the-birth-of-the-web/where-web-was-born/)
10. [nginx, nginx.org](https://nginx.org/en/)
11. [Automatic HTTPS, Caddy documentation](https://github.com/caddyserver/website/blob/master/src/docs/markdown/automatic-https.md)
12. [Netcraft Web Server Survey](https://www.netcraft.com/resources/web-server-survey)
13. [Multi-Processing Modules (MPMs), Apache HTTP Server Version 2.4](https://d.apache.org/docs/current/mpm.html)
14. [The Apache HTTP Server Project](https://d.apache.org/)
15. [RFC 9112: HTTP/1.1, IETF, June 2022](https://www.ietf.org/rfc/rfc9112.pdf)
16. [RFC 9114: HTTP/3, IETF](https://datatracker.ietf.org/doc/rfc9114/)
17. [Module ngx_http_v3_module, nginx documentation](https://nginx.org/en/docs/http/ngx_http_v3_module.html?trk=public_post_comment-text)
18. [Denial of Service Cheat Sheet, OWASP](https://cheatsheetseries.owasp.org/cheatsheets/Denial_of_Service_Cheat_Sheet.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/web-server

English original: https://www.edgepedia.org/web-server
