非常简单的问题:
在 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/