Jump to content

[OPTIMISATION] Nginx + PageSpeed mod : MUST HAVE :)

Recommended Posts

Hello everybody.



When your website is online, the first occupation is to get a fast website.

You can analyze your website with google tools - page speed : 




Then to fixed items, once of good ways is to get the pagespeed module installed on your webserver.

The module is available on Apache and Nginx (I only tried it on Nginx - The best/reliable server) :D


Its my nginx configuration - We can share tips/advice on this thread ;)

# enable ngx_pagespeed
        pagespeed on;

        pagespeed FileCachePath /var/ngx_pagespeed_cache;

        # disable CoreFilters
        pagespeed RewriteLevel PassThrough;

        # enable collapse whitespace filter
        pagespeed EnableFilters collapse_whitespace;

        # enable JavaScript library offload
        pagespeed EnableFilters canonicalize_javascript_libraries;

        # combine multiple CSS files into one
        pagespeed EnableFilters combine_css;

        # combine multiple JavaScript files into one
        pagespeed EnableFilters combine_javascript;

        # remove tags with default attributes
        pagespeed EnableFilters elide_attributes;

        # improve resource cacheability
        pagespeed EnableFilters extend_cache;

        # flatten CSS files by replacing @import with the imported file
        pagespeed EnableFilters flatten_css_imports;
        pagespeed CssFlattenMaxBytes 5120;

        # defer the loading of images which are not visible to the client
        pagespeed EnableFilters lazyload_images;

        # enable JavaScript minification
        pagespeed EnableFilters rewrite_javascript;

        # enable image optimization
        pagespeed EnableFilters rewrite_images;

        # pre-solve DNS lookup
        pagespeed EnableFilters insert_dns_prefetch;

        # rewrite CSS to load page-rendering CSS rules first.
        pagespeed EnableFilters prioritize_critical_css;

With OpCache, PHP-APC and memcached installed its sooooo good ;-)



  • Like 2

Share this post

Link to post
Share on other sites



thank you for tip!


Can you please share your whole nginx config for prestashop?


Because I have problems to solve friendly urls.


Thank you!

Share this post

Link to post
Share on other sites

Yep :


for url rewriting :

rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/order$ /index.php?controller=order last;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php last;

The rest of my nginx configuration is here : https://www.prestashop.com/forums/topic/433612-nginxphpssl-on-vps-ttfb-8secs/?do=findComment&comment=2015410

Share this post

Link to post
Share on other sites

i have problem in BO since i'm using mod_pagespeed.

I love it but cant edit products anymore.. 


I tried disabling pagespeed in backoffice in these ways, but still no use:


location /admin {
pagespeed Off;

pagespeed Disallow "*/jquery-1.11.0.min.js";
pagespeed Disallow "*/js/jquery/jquery-1.11.0.min.js";
any clues??

Share this post

Link to post
Share on other sites

Hi, I had all your pagespeed options set up, but I'm not getting "good" results. I was expecting more improvements.

I only have opcache installed, because somewhere I read that MemCached was designed to balance the load between different servers. And that if you only have one, it's not worth it.

I will discuss how to add APC.


Here is pagespeed configuration:

pagespeed on;
pagespeed ImplicitCacheTtlMs 1800000;
pagespeed RewriteLevel OptimizeForBandwidth;

#Change origin header cache control
pagespeed ModifyCachingHeaders on;

pagespeed HonorCsp on;
pagespeed RespectVary on;
pagespeed PreserveUrlRelativity on;
pagespeed DisableRewriteOnNoTransform off;
pagespeed AllowVaryOn Auto;
# if memcached is installed and on default port
#pagespeed MemcachedServers "localhost";

pagespeed EnableFilters add_head;

#AdSense Optimization.
pagespeed EnableFilters make_show_ads_async;

pagespeed EnableFilters add_instrumentation;
pagespeed ReportUnloadTime on;
pagespeed EnableFilters include_js_source_maps;

#HTTPS Support Enable.
pagespeed FetchHttps enable;
pagespeed FetchHttps enable,allow_self_signed;

#Optimize Browser Filters.
pagespeed EnableFilters hint_preload_subresources;
pagespeed EnableFilters convert_meta_tags;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters remove_quotes;

#HTML Optimization.
pagespeed EnableFilters combine_heads;
pagespeed EnableFilters elide_attributes;
pagespeed EnableFilters remove_comments;
pagespeed RetainComment " google_ad_section*";

#Image Optimization filters.
pagespeed EnableFilters convert_jpeg_to_webp;
pagespeed EnableFilters convert_to_webp_lossless;
pagespeed EnableFilters inline_images;
pagespeed EnableFilters insert_image_dimensions;
pagespeed EnableFilters recompress_webp;
pagespeed EnableFilters resize_images;
pagespeed CssImageInlineMaxBytes 5000;
pagespeed ImageInlineMaxBytes 3072;
pagespeed EnableFilters inline_preview_images;
pagespeed EnableFilters recompress_images;
pagespeed ForbidFilters convert_png_to_jpeg;
pagespeed EnableFilters convert_jpeg_to_progressive;
pagespeed LazyloadImagesBlankUrl "https://www.gstatic.com/psa/static/1.gif";
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters resize_rendered_image_dimensions;
pagespeed FinderPropertiesCacheExpirationTimeMs 720000000;
pagespeed LazyloadImagesAfterOnload off;
pagespeed EnableFilters dedup_inlined_images;
pagespeed EnableFilters responsive_images;
pagespeed EnableFilters resize_mobile_images;
pagespeed EnableFilters jpeg_subsampling;
pagespeed EnableFilters convert_to_webp_animated;
pagespeed EnableFilters responsive_images_zoom;
pagespeed EnableFilters lazyload_images;

#JavaScript Optimization Filters.
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters inline_javascript;
pagespeed JsInlineMaxBytes 50000;
pagespeed MaxCombinedJsBytes -1;
pagespeed MaxSegmentLength 250;
pagespeed EnableFilters outline_javascript;
pagespeed JsOutlineMinBytes 30000;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters canonicalize_javascript_libraries;
#pagespeed EnableFilters defer_javascript;

#CSS Optimization Filters.
pagespeed EnableFilters prioritize_critical_css;
#pagespeed EnableFilters inline_css;
#pagespeed CssInlineMaxBytes 151200;
pagespeed EnableFilters rewrite_css;
pagespeed EnableFilters fallback_rewrite_css_urls;
pagespeed EnableFilters sprite_images;
pagespeed EnableFilters inline_google_font_css;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed GoogleFontCssInlineMaxBytes 51200;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters combine_css;
pagespeed MaxCombinedCssBytes -1;
#pagespeed CombineAcrossPaths off;
pagespeed EnableFilters inline_import_to_link;

#Other Optimization Filters.
pagespeed EnableFilters insert_dns_prefetch;
pagespeed EnableFilters rewrite_domains;
pagespeed DomainRewriteHyperlinks on;
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 100000;
pagespeed EnableFilters trim_urls;
pagespeed RewriteLevel PassThrough;
pagespeed EnableCachePurge on;
pagespeed PurgeMethod PURGE;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters local_storage_cache;

#Compress cache.
pagespeed HttpCacheCompressionLevel 9;

pagespeed InPlaceResourceOptimization on;

#Enable PageSpeed Statistics and Logging.
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir "/var/www/vhosts/domain.com/domain.com/var/pagespeed/log";

#location ~ ^/pagespeed_admin { include common/acl.conf; }
#location ~ ^/ngx_pagespeed_statistics { include common/acl.conf; }

#Server-Side Cache
pagespeed FileCachePath "/var/www/vhosts/domain.com/domain.com/var/pagespeed/cache";
pagespeed FileCacheSizeKb            10000000;
pagespeed FileCacheCleanIntervalMs   604800000;
pagespeed FileCacheInodeLimit        500000;

pagespeed UrlSigningKey signature_key_string;
pagespeed AcceptInvalidSignatures true;

#Respecting X-Forwarded-Proto
pagespeed RespectXForwardedProto on;

#pagespeed ListOutstandingUrlsOnError on;
#pagespeed MaxCacheableContentLength -1;


pagespeed Domain domain.com;
pagespeed Domain *.domain.com;

pagespeed LRUCacheKbPerProcess 8192;
pagespeed LRUCacheByteLimit 16384;
pagespeed CssOutlineMinBytes 3000;
pagespeed EnableFilters strip_image_meta_data;
#pagespeed MessageBufferSize 100000;
pagespeed EnableFilters recompress_jpeg;
pagespeed EnableFilters recompress_png;

#pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
#pagespeed GlobalAdminPath /pagespeed_global_admin;
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed AdminPath /pagespeed_admin;

# Statistics location blocks
#location /ngx_pagespeed_global_statistics { allow; deny all; }
#location ~ ^/pagespeed_global_admin { allow; deny all; }
location /ngx_pagespeed_statistics { allow; deny all; }
location /ngx_pagespeed_message { allow; deny all; }
location /pagespeed_console { allow; deny all; }
location ~ ^/pagespeed_admin { allow; deny all; }

# Default PageSpeed location blocks
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
	add_header "" "";
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }


Share this post

Link to post
Share on other sites

ngnix with https2 on dedicated with nvme/ssd is now getting near good vps costs!  last year nvme was 200 a month, still is for lagging hosting.  Now we are seeing nvme 


and ovh example


we do the nvme and other performance tuning then setup the mysql config properly, all hosting out of box have poor mysql default settings

happy webmastering

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More