HTTP/2 哪个更好:Apache vs Nginx?
What is better with HTTP/2: Apache vs Nginx?
我正在为具有数十个 JS 和 css 文件的大型 SPA 应用程序选择一个更好的 Web 服务器。使用 HTTP/2,我们现在无法将它们合并为两个大文件(JS 为 3 MB),在慢速连接时需要很长时间才能加载。但是哪个服务器更适合新的 HTTP/2 范例?
Nginx 是为解决http/1 问题而设计的,它的优点是可以更好地服务于大量连接,HTTP/2 所有文件只有一个连接,所以这个功能现在看来是多余的。你怎么看,你能给我什么建议?
这是一个非常主观的问题,可能不适合 Whosebug,所以想象一下这会被关闭。但这是我的两分钱...
完全披露:我主要使用 Apache。
首先,让我们解决您的一个错误观点:Nginx 并非旨在解决 HTTP/1 问题。 Nginx 旨在通过基于异步 event-driven 模型来解决以前 Web 服务器的一些可扩展性问题。在 HTTP/2 下,每个客户端的连接应该更少,您可能会争辩说,这使得可伸缩性不再是一个问题,因为每个客户端只使用了他们以前使用的资源的 1/6 - 但这可能有点简单化。 Apache has an event-driven MPM module for years now too (though often not turned on by default in case of any thread unsafe PHP applications - but this would also be a problem with Nginx!). This brings them more back in line, though there's still a lot of debate about this and many say Nginx is still faster. In my experience, unless you are dealing with truly huge volumes (in which case you should be looking at CDNs, load-balancers and cache accelerators), few will ever notice the difference between Nginx and Apache. This is especially true when downstream applications and systems come into play - a slow PHP application will quickly negate any performance or scalability issues at the web server level.
无论如何,回到你的主要问题:
为了 HTTP/2 支持,我的选择是 Apache 而不是 Nginx。一段时间以来,它得到了更好的 HTTP/2 支持。 Nginx only added HTTP/2 Push support in early 2018 for example, whereas Apache has had that for a number of years now. Apache also supports a PushDiary (based on the now-abandon Cache-Digests proposal) to prevent pushing resources that have already been sent, supports 103 Early Hints for pushing early, and push prioritisation options. Moving on from HTTP/2 push, Apache also supports using HTTP/2 in proxy mode (though it's still marked as experimental and the usefulness of this is questionable at the moment), and HTTP/2 over HTTP (h2c - though again usefulness is questionable since browsers do not support this). I also find the main developer of the Apache HTTP/2 implementation very responsive on the GitHub page for the mod_http2 module(自 2.4.18 起作为核心 Apache 的一部分,自 2.4.26 起不再标记为“实验性”)。
另一方面,据我所知,Cloudflare 使用基于 Nginx 的自定义 Web 服务器,并且他们已经 HTTP/2 推送了一年多(正是他们将此实现反向移植到 Nginx)。所以,given Cloudflare's scale, that speaks volumes to the implementation of that though not sure how customised it is from the core Nginx code.
还有一个 HTTP/2 conformance Testing tool available and when I ran this against some common HTTP/2 servers (for a book I wrote on the subject btw) 我得到了以下结果,清楚地表明 Apache 最符合规范:
现在说句公道话,错误的大部分原因是没有正确响应错误的请求,在完美的世界中无论如何都不应该发送这些请求,所以这并不重要。但是,我们仍然没有生活在一个完美的世界中,错误检查是技术的重要组成部分,所以我当然更喜欢更合规的服务器。与下面评论中指出的类似,该工具和 Web 服务器本身可能会受到竞争条件和其他可能错误报告错误的问题的影响。
最终,您最好选择您最满意的实施方式。一般的感觉一直是 Nginx 更轻便且更易于配置,但另一方面可能因此不如 Apache 功能齐全。 HTTP/2 支持似乎延续了这一主题。如果您想使用即将推出的 HTTP/2 功能,那么对我来说,Apache 目前绝对具有优势(尽管没有说将来不会改变)。但是,对于 HTTP/2 的基本用例,它们可能可以被认为是相似的。甚至 HTTP/2 Push 还没有被广泛使用,并且存在严重的担忧 it could degrade performance if not used appropriately or due to implementation issues,这可能是为什么它一直不是 Nginx 的优先事项,而他们后来才实现它。
我正在为具有数十个 JS 和 css 文件的大型 SPA 应用程序选择一个更好的 Web 服务器。使用 HTTP/2,我们现在无法将它们合并为两个大文件(JS 为 3 MB),在慢速连接时需要很长时间才能加载。但是哪个服务器更适合新的 HTTP/2 范例?
Nginx 是为解决http/1 问题而设计的,它的优点是可以更好地服务于大量连接,HTTP/2 所有文件只有一个连接,所以这个功能现在看来是多余的。你怎么看,你能给我什么建议?
这是一个非常主观的问题,可能不适合 Whosebug,所以想象一下这会被关闭。但这是我的两分钱...
完全披露:我主要使用 Apache。
首先,让我们解决您的一个错误观点:Nginx 并非旨在解决 HTTP/1 问题。 Nginx 旨在通过基于异步 event-driven 模型来解决以前 Web 服务器的一些可扩展性问题。在 HTTP/2 下,每个客户端的连接应该更少,您可能会争辩说,这使得可伸缩性不再是一个问题,因为每个客户端只使用了他们以前使用的资源的 1/6 - 但这可能有点简单化。 Apache has an event-driven MPM module for years now too (though often not turned on by default in case of any thread unsafe PHP applications - but this would also be a problem with Nginx!). This brings them more back in line, though there's still a lot of debate about this and many say Nginx is still faster. In my experience, unless you are dealing with truly huge volumes (in which case you should be looking at CDNs, load-balancers and cache accelerators), few will ever notice the difference between Nginx and Apache. This is especially true when downstream applications and systems come into play - a slow PHP application will quickly negate any performance or scalability issues at the web server level.
无论如何,回到你的主要问题:
为了 HTTP/2 支持,我的选择是 Apache 而不是 Nginx。一段时间以来,它得到了更好的 HTTP/2 支持。 Nginx only added HTTP/2 Push support in early 2018 for example, whereas Apache has had that for a number of years now. Apache also supports a PushDiary (based on the now-abandon Cache-Digests proposal) to prevent pushing resources that have already been sent, supports 103 Early Hints for pushing early, and push prioritisation options. Moving on from HTTP/2 push, Apache also supports using HTTP/2 in proxy mode (though it's still marked as experimental and the usefulness of this is questionable at the moment), and HTTP/2 over HTTP (h2c - though again usefulness is questionable since browsers do not support this). I also find the main developer of the Apache HTTP/2 implementation very responsive on the GitHub page for the mod_http2 module(自 2.4.18 起作为核心 Apache 的一部分,自 2.4.26 起不再标记为“实验性”)。
另一方面,据我所知,Cloudflare 使用基于 Nginx 的自定义 Web 服务器,并且他们已经 HTTP/2 推送了一年多(正是他们将此实现反向移植到 Nginx)。所以,given Cloudflare's scale, that speaks volumes to the implementation of that though not sure how customised it is from the core Nginx code.
还有一个 HTTP/2 conformance Testing tool available and when I ran this against some common HTTP/2 servers (for a book I wrote on the subject btw) 我得到了以下结果,清楚地表明 Apache 最符合规范:
现在说句公道话,错误的大部分原因是没有正确响应错误的请求,在完美的世界中无论如何都不应该发送这些请求,所以这并不重要。但是,我们仍然没有生活在一个完美的世界中,错误检查是技术的重要组成部分,所以我当然更喜欢更合规的服务器。与下面评论中指出的类似,该工具和 Web 服务器本身可能会受到竞争条件和其他可能错误报告错误的问题的影响。
最终,您最好选择您最满意的实施方式。一般的感觉一直是 Nginx 更轻便且更易于配置,但另一方面可能因此不如 Apache 功能齐全。 HTTP/2 支持似乎延续了这一主题。如果您想使用即将推出的 HTTP/2 功能,那么对我来说,Apache 目前绝对具有优势(尽管没有说将来不会改变)。但是,对于 HTTP/2 的基本用例,它们可能可以被认为是相似的。甚至 HTTP/2 Push 还没有被广泛使用,并且存在严重的担忧 it could degrade performance if not used appropriately or due to implementation issues,这可能是为什么它一直不是 Nginx 的优先事项,而他们后来才实现它。