Tuesday, 4 April 2017

Nginx - gzip_static and proxy_pass - proper way to serve static gzip files

What is the best way to serve static gzip files using nginx of a server that runs thru a proxy?

I have a nodejs app running thru a proxy_pass http://127.0.0.1:3000/;

I'd like to pass through nodejs (without touching) to static gzip files when possible.

Current configuration:

  • project's folder with files and their compressed copies
  • nodejs project running on 127.0.0.1:3000
  • the following short version of my nginx.conf `

    http {
    
    gzip on;
    gzip_disable msie6;
    gzip_comp_level 1;
    gzip_vary on;
    gzip_proxied expired no-cache no-store private;
    gzip_types text/plain text/xml text/javascript text/css application/json application/javascript application/x-javascript;
    
    server {
        listen 443 ssl;
        server_name domain.com;
        location / {
            proxy_pass http://127.0.0.1:3000/;
            proxy_http_version 1.1;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header Host $http_host;
            proxy_ssl_session_reuse off;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
        }
    }
    }
    
    

`

As I understand, I can't set gzip_static on; with the proxy_pass, so I should probably create a separate location that specifies the root path/to/static/files

Would be glad to all comments, thank you!



via Olzhas Alexandrov

No comments:

Post a Comment