[英]does nginx support compress the request to the upstream?
Dose nginx supprt this ? 剂量nginx支持吗? Whoul you please show me some configuration of it?
你能告诉我一些配置吗?
[Client] [Nginx Reverse Proxy] [BackEnd]
| [Raw Post] | [gzip encoded request] |
|--------------------> | ----------------------------->|
| | |
| [Raw Response] | [gzip encoded response] |
| <------------------ | <-----------------------------|
| | |
Apparently there is some way to do this. 显然有一些方法可以做到这一点。 Nginx has a
gunzip
module that gzip decompresses responses: Nginx有一个
gunzip
模块,gzip解压缩响应:
The ngx_http_gunzip_module module is a filter that decompresses responses with “Content-Encoding: gzip” for clients that do not support “gzip” encoding method.
ngx_http_gunzip_module模块是一个过滤器,它使用“Content-Encoding:gzip”解压缩响应,用于不支持“gzip”编码方法的客户端。 The module will be useful when it is desirable to store data compressed, to save space and reduce I/O costs.
当需要存储压缩数据,节省空间和降低I / O成本时,该模块将非常有用。
This module is not built by default, it should be enabled with the --with-http_gunzip_module configuration parameter.
默认情况下不构建此模块,应使用--with-http_gunzip_module配置参数启用它。
Source: http://nginx.org/en/docs/http/ngx_http_gunzip_module.html 来源: http : //nginx.org/en/docs/http/ngx_http_gunzip_module.html
Then you can use it like: 然后你就可以使用它:
gunzip on;
Hope that works for you. 希望对你有用。
Also see this SO question: Is there sort of unzip modules in nginx? 另请参阅这个问题: nginx中是否有类似的解压缩模块?
The full and correct answer is that nginx can do this, but with a couple of caveats. 完整而正确的答案是nginx 可以做到这一点,但有一些警告。 In order to provide an uncompressed response to the edge client (user PC), you must compile nginx with the
gunzip
module - which isn't built/included by default. 为了向边缘客户端(用户PC)提供未压缩的响应,必须使用
gunzip
模块编译nginx - 默认情况下不构建/包含该模块。 This is the opposite of the gzip module, and allows nginx to unzip already-compressed resources found on disk or obtained from a backend server. 这与gzip模块相反,允许nginx解压缩在磁盘上找到的或从后端服务器获取的已压缩资源。
So when compiling nginx, include this: --with-http_gunzip_module
所以在编译nginx时,请包括:--
--with-http_gunzip_module
And in your nginx.conf
, you'll have a block like this to describe requests to be obtained from a backend server: 在你的
nginx.conf
,你将有一个这样的块来描述从后端服务器获取的请求:
location @backend {
...
proxy_pass http://10.0.0.xxx;
gunzip on;
proxy_set_header Accept-Encoding "gzip";
}
You can turn off gzip compression in nginx by setting the gzip
directive to off
in your nginx.conf
: 您可以通过在
nginx.conf
中将gzip
指令设置为off
来off
nginx中的gzip压缩:
gzip off
Additionally you can turn of gzip compression for proxied requests only: 此外,您只能为代理请求启用gzip压缩:
gzip_proxied off
Nginx has a great wiki where all this information is clearly explained: http://wiki.nginx.org/HttpGzipModule Nginx有一个很棒的维基,其中清楚地解释了所有这些信息: http : //wiki.nginx.org/HttpGzipModule
About nginx proxying: also clearly described in the nginx wiki: 关于nginx代理:在nginx wiki中也有明确描述:
Example:
例:
location / { proxy_pass http://localhost:8000; proxy_set_header X-Real-IP $remote_addr; }
http://wiki.nginx.org/HttpProxyModule http://wiki.nginx.org/HttpProxyModule
There are many different ways to set up a proxy so you should dive in and see what you need exactly, there's no 'one' answer to this. 有许多不同的方法来设置代理,所以你应该深入了解你需要什么,对此没有“一个”答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.