Nginx Reverse Proxy SSL / Minification

I am trying to use NginX as a reverse proxy for multiple IIS servers. The goal is for NginX to work with IIS / Apache servers, caching static elements like CSS / JS / Images. I am also trying to get NginX to automatically minimize js / css files using my perl module.

I found a sample script to evaluate here:

http://petermolnar.eu/linux-tech-coding/nginx-perl-minify-css-js/

With a script, everything works fine except for breaking the reverse proxy.

Questions:

  • I'm trying to do what can I do? I want NginX to minimize scripts first before storing them in the cache.
  • Can nginX automatically sets the correct expiration headers so that static elements are cached for as long as possible and only replaced when querystrings change (jquery.js? Timestamp = march-2012).
  • Can NginX GZIP use resources before sending them.
  • Can NGinx forward requests or serve the Down For Service page if it cannot connect to the end server.

Any help would be greatly appreciated.

Here is what I have on my enabled / default sites.

server { location / { proxy_pass http://mywebsite.com; proxy_set_header Host $host; proxy_cache STATIC; proxy_cache_valid 200 1d; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; } location @minify { perl Minify::minify_handler; } location ~ \.css$ { try_files $uri.min.css @minify; } location /*.js { expires 30d; } } 
+4
source share
1 answer

Nginx is the perfect solution for a reverse proxy server, as well as Unix's way of "doing one thing and doing it well." Therefore, I would advise you to separate the content processing and the thumbnail process, instead of using third-party plugins, to do many things at the same time.

The best practice is to minimize and phase the obfuscate in the local system before deployment in production, this is easy to say and not difficult to do, see google way for compressing static assets. When you purchase ready-to-use assets, we can configure the nginx configuration.

Answers:

  • use minify & obfuscate before deploying it in production

  • you can find assets by regexp (directory name or file extension)

    location ~ ^ / (assets | images | javascripts | stylesheets | swfs | system) / {gzip_static on; expax max; add_header Cache-Control public; add_header Last-Modified "; add_header ETag" "; break;}

  • use gzip on and gzip_static on to serve gzipped files, rather than compressing them every time you get a request.

  • use try_files to detect the service page or not

    try_files $ uri / system / maintenance.html @mywebsite;

    if (-f $ document_root / system / maintenance.html) {return 503; }

See the full nginx configuration for your case:

 http { keepalive_timeout 70; gzip on; gzip_http_version 1.1; gzip_disable "msie6"; gzip_vary on; gzip_min_length 1100; gzip_buffers 64 8k; gzip_comp_level 3; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml application/xml; upstream mywebsite { server 192.168.0.1 # change it with your setting } server { try_files $uri /system/maintenance.html @mywebsite; location @mywebsite { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://mywebsite; } location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { gzip_static on; expires max; add_header Cache-Control public; add_header Last-Modified ""; add_header ETag ""; break; } if (-f $document_root/system/maintenance.html) { return 503; } location @503 { error_page 405 = /system/maintenance.html; if (-f $document_root/system/maintenance.html) { rewrite ^(.*)$ /system/maintenance.html break; } rewrite ^(.*)$ /503.html break; } } } 
+5
source

All Articles