Question

I am trying to find the best approach for my nginx box. My goal is, of course, the best possible performance, and the best loading times for my users.

So I was load testing my nginx and - with the help of maxim-dounin from nginx forums - found out that my throughput problems was on the fly gzipping of static assets.

I'll have to pre-gzip everything on the build process, thats very easy - and do on the fly gzip for dynamic content only with comp level @ 1 or 2, that shoud save some cpu and allow me to serve as many users as possible with aws m1.small ec2 instance.

But I also intent to use ngx_pagespeed to optimize these static assets, minify, combine, stuff that ngx_pagespeed does so well. I mean, images I can work around and do jpgoptim and pngoptim on build process, but combining css/js is harder.

I am using these ngx_pagespeed config:

pagespeed on;
pagespeed EnableFilters combine_css,combine_javascript,canonicalize_javascript_libraries,collapse_whitespace,convert_meta_tags,dedup_inlined_images,flatten_css_imports,inline_import_to_link,inline_css,inline_javascript,rewrite_javascript,remove_comments,rewrite_css,rewrite_images,convert_gif_to_png,recompress_png,convert_jpeg_to_progressive,strip_image_color_profile,strip_image_meta_data,insert_image_dimensions;
pagespeed JpegRecompressionQuality 80;
pagespeed FileCacheSizeKb            256000; #256mb
pagespeed FileCacheCleanIntervalMs   3600000;
pagespeed FileCacheInodeLimit        500000;
pagespeed FileCachePath /run/shm/nginx/pagespeed_cache;
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir /var/log/pagespeed;
pagespeed LowercaseHtmlNames on;

Any ideias on how ngx_pagespeed works with nginx gzip_static? I mean, as far as my understaing go, ngx_pagespeed is running 'in front' of nginx, as it caches everything it optimizes to tmpfs. If the server got a hit for a already optimized asset it servers from tmpfs, and I looked for gzipped files on the cache folder and could not find any. First of all, ngx_pagespeed does its own gzipping? It does it on the fly or it cache gzipped version?

How does it go when it receives an already gzipped asset from nginx (gzip_static on)? Does it have to unzip and then gzip again after optimization?

How can I have the best of both worlds - serving pre-compressed static assets and ngx_pagespeed optimizations?

Thanks alot and best regards.

Was it helpful?

Solution

I was able to accomplish my objective by putting Varnish in front of Nginx. Varnish caches gziped version of assets and of the pages. ngx_pagespeed Downstream Cache purge (check nxg_pagespeed docs for more info) is working as it is supposed to by sending PURGE requests to varnish when the optimization (running on background I guess) is complete. The performance is great now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top