title: Compressing assets with NGINX in reverse proxy mode
body: <p>I'm using NGINX as a reverse proxy in front of a Node.js app. The basic proxy works perfectly fine and I'm able to compress assets on the Node server with <code>compression</code> middleware.</p>
  
  <p>To test if it's possible to delegate the compression task to NGINX, I've disabled the middleware and now I'm trying to gzip with NGINX with the following configuration:</p>
  
  <pre><code>worker_processes 1;
  
  events {
      worker_connections 1024;
  }
  
  http {
      include mime.types;
      default_type application/octet-stream;
      sendfile on;
      keepalive_timeout 300;
      server {
          listen 80;
  
          ## gzip config
          gzip on;
          gzip_min_length 1000;
          gzip_comp_level 5;
          gzip_proxied any;
          gzip_vary on;
          gzip_types text/plain
                     text/css
                     text/javascript
                     image/gif
                     image/png
                     image/jpeg
                     image/svg+xml
                     image/x-icon;
  
          location / {
              proxy_pass http://app:3000/;
              proxy_http_version 1.1;
  
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_cache_bypass $http_upgrade;
              }
      }
  }
  </code></pre>
  
  <p>With this configuration, NGINX doesn't compress the assets. I've tried declaring these in the <code>location</code> context with different options but none of them seems to do the trick.</p>
  
  <p>I couldn't find relevant resources on this so I'm questioning if it could be done this way at all.</p>
  
  <p>Important points:</p>
  
  <p>1- Node and NGINX are on different containers so I'm not serving the static assets with NGINX. I'm just proxying to the node server which is serving these files. All I'm trying to achieve is offload the node server with getting NGINX to do the gzipping.</p>
  
  <p>2- I'm testing all the responses with "Accept-Encoding: gzip" enabled.</p>