I have plenty of HTTP POST requests being sent to a nginx server that then get load balanced to a set of reversed proxied node.js/express.js backend servers. To spare some network consumption the payload is being sent using GZIP and header Content-Encoding: gzip.
I'm trying to achieve something like this:
[Client] [Nginx Reverse Proxy] [BackEnd]
| [gziped payload] | [raw payload] |
|--------------------> | ----------------------------->|
| | |
| [Raw Response] | [Raw response] |
| <------------------ | <-----------------------------|
| | |
For efficiency reasons i want to run Gunzip at Nginx yet i haven't been able to do so. Here's the http nginx.conf file:
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;
}
}
}
Here's an example of a request:
echo "{"id": 0,"mypayload":"This is an example"}" | gzip -c - | curl -v -i -X POST -H 'Content-Encoding: gzip' --data-binary '@-' http://localhost/test
I wanted nginx to unzip the content of the payload and deliver the raw content to the backend server, yet the content is still being delivered compressed.
I've seen plenty of folks doing the other way around (Nginx gziping responses and even gunzipping responses to clients that do not have the Accept-Encoding: gzip header) yet couldn't find it successfully gunziping payloads to the backend.
Any clues?