Nginx可以对websocket连接进行透明压缩吗?

时间:2019-03-20 07:39:02

标签: nginx websocket proxy compression gzip

我让nginx充当ASP.net/Kestrel后端服务器的反向代理。

我希望nginx为我的Websocket连接进行gzip压缩(即permessage-deflate / rfc7692),但找不到任何配置选项。

nginx可以这样做吗?是否有任何插件可以使其正常工作?如果没有,我还有其他可以使用的东西吗?

1 个答案:

答案 0 :(得分:0)

只需编辑您的nginx配置。对于静态网站,代理或网络套接字来说都是一样的

gunzip on; // be sure to include this. This enables runtime decompression for clients that do not accept gzip
gzip on; //enables gzip for request
gzip_proxied any; //enables compression on proxies
gzip_types *; //compress everything there is

如果这不起作用,请尝试压缩消息,然后再通过套接字发送消息。 您可以在这里了解更多信息:https://docs.nginx.com/nginx/admin-guide/web-server/compression/