java - Spring 服务器或 Nginx(反向代理)上的 Gzip?

标签 java spring-boot nginx

非常简单的问题:

在 Spring 服务器上启用 gzip 与在 Spring 服务器上启用 gzip 有何优缺点? nginx? Spring Server 仅用于服务 RESTful api 请求(json),Nginx 在 Spring 服务器之前用作反向代理

我四处搜寻,但似乎没有人有很好的答案。这个答案( Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful )讨论了应该在 nginx 上启用它,因为它更高效(IRL 人们这样做)

所以我想知道是否有人有这方面的经验?人们通常做什么?

最佳答案

如果你关心性能:不要使用 Nginx!

Nginx gzip 进程是一个内容过滤器,这与 send_file 优化不兼容(更多详细信息请参见 https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/#enabling-sendfile ):

Enabling the sendfile directive eliminates the step of copying the data into the buffer and enables direct copying data from one file descriptor to another.

因此,我建议使用 HTTP 代理(您可以使用另一个 Nginx!我一直在做的事情),并设置 proxy_cache:

Nginx --(代理缓存)--> Nginx -- gzip --> CSS/JS 文件

关于java - Spring 服务器或 Nginx(反向代理)上的 Gzip?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63788742/

相关文章:

java - 匹配一个或多个数字 1-9、一个 '|' 、一个或多个 '*"和零个或多个 ',' 的正则表达式

java - 在Java中存储键值

java - 我可以使用 Hibernate 对特定整数大小执行验证吗?

javascript - 在 JavaScript 中动态加载的绘制到 Canvas 上的图像具有不正确(但接近)的 RGB 值

NGINX 上游超时 (110 : Operation timed out)

java - 按钮的新 setText 属性无缘无故出现空指针异常

java - Spring ThreadPoolTask​​Executor 只运行一个线程

java - 如何在执行 'Unsupported class file major version 55' 时修复 'org.apache.spark.sql.DataSet.collectAsList()'

amazon-web-services - 使用@SqsListener时,Spring Boot应用程序启动时失败

ruby - nginx配置有什么问题?