【发布时间】:2015-06-28 06:09:53
【问题描述】:
我有大量的 HTTP POST 请求被发送到 nginx 服务器,然后将负载平衡到一组反向代理 node.js/express.js 后端服务器。为了节省一些网络消耗,使用 GZIP 和标头 Content-Encoding: gzip 发送有效负载。
我正在尝试实现这样的目标:
[Client] [Nginx Reverse Proxy] [BackEnd]
| [gziped payload] | [raw payload] |
|--------------------> | ----------------------------->|
| | |
| [Raw Response] | [Raw response] |
| <------------------ | <-----------------------------|
| | |
出于效率原因,我想在 Nginx 上运行 Gunzip,但我无法这样做。这是 http nginx.conf 文件:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
gunzip on;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
这是一个请求示例:
echo "{"id": 0,"mypayload":"This is an example"}" | gzip -c - | curl -v -i -X POST -H 'Content-Encoding: gzip' --data-binary '@-' http://localhost/test
我希望 nginx 解压缩有效负载的内容并将原始内容传送到后端服务器,但内容仍被压缩传送。
我看到很多人在做相反的事情(Nginx gziping 响应,甚至是对没有 Accept-Encoding: gzip 标头的客户端的响应)但无法找到它成功地将有效负载压缩到后端。
有什么线索吗?
【问题讨论】:
-
您找到问题的答案了吗?你最终经历了什么过程?
-
@bibstha 现在我正在后端进行 gzip 解码。如果我找不到使用 Nginx 的替代方案,我可能会在 Nginx 之后开发一个反向代理简单的反向代理来执行此操作,或者编写一个 LUA 模块来处理这些情况。
标签: node.js nginx reverse-proxy gunzip