Want to subscribe to topics you're interested in?
Become a Member

Nginx PageSpeed This forum's pagespeed.conf

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by eva2000, May 26, 2014.

  1. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    Dedicated thread to keep a tally and history of this forum's pagespeed.conf changes and settings for Nginx PageSpeed module. Update mod_pagespeed and ngx_pagespeed documentation is now listed together at https://modpagespeed.com/doc/

    current /usr/local/nginx/conf/pagespeed.conf configuration used on this very forum as follows:
    Code:
    pagespeed on;
    
    pagespeed LoadFromFile "http://community.centminmod.com" "/home/nginx/domains/community.centminmod.com/public";
    pagespeed LoadFromFile "https://community.centminmod.com" "/home/nginx/domains/community.centminmod.com/public";
    
    pagespeed LoadFromFileRuleMatch disallow .*;
    pagespeed LoadFromFileRuleMatch allow \.css$;
    pagespeed LoadFromFileRuleMatch allow \.jpe?g$;
    pagespeed LoadFromFileRuleMatch allow \.png$;
    pagespeed LoadFromFileRuleMatch allow \.gif$;
    pagespeed LoadFromFileRuleMatch allow \.js$;
    
    pagespeed Disallow */js/dark/postrating.js*;
    pagespeed Disallow */js/xenforo/tabalerts.js*;
    pagespeed Disallow */lost-password/lost;
    pagespeed Disallow */lost-password/*;
    pagespeed Disallow */payment_callback.php*;
    pagespeed Disallow */munin/*;
    pagespeed Disallow */admincp/*;
    pagespeed Disallow */cron.php*;
    pagespeed Disallow */admin.php*;
    pagespeed Disallow */css.php*;
    pagespeed Disallow */js/jquery/jquery-1.11.0.min.js*;
    pagespeed Disallow */js/xenforo/xenforo.js*;
    pagespeed Disallow */mark-read*;
    pagespeed Disallow */forums/-/mark-read*;
    pagespeed Disallow */reply/preview*;
    pagespeed Disallow */account/alerts-popup*;
    pagespeed Disallow */conversations/popup*;
    pagespeed Disallow */conversations/*;
    pagespeed Disallow */account/alerts/*;
    pagespeed Disallow */?card*;
    pagespeed Disallow */misc/quick-navigation-menu*;
    pagespeed Disallow */misc/update-cache-ttl*;
    pagespeed Disallow */deferred.php*;
    pagespeed Disallow */forums/*;
    pagespeed Disallow */attachments/*;
    pagespeed Disallow */rgba.php*;
    pagespeed Disallow */add-reply*;
    pagespeed Disallow */edit-inline*;
    pagespeed Disallow */save-inline*;
    pagespeed Disallow */posts/*/save-inline*;
    pagespeed Disallow */posts/*/edit*;
    pagespeed Disallow */posts/*/delete*;
    pagespeed Disallow */posts/*/ip*;
    pagespeed Disallow */posts/*/report*;
    pagespeed Disallow */proxy.php*;
    
    #######################################################
    # File cache settings
    ######################################
    # needs to exist and be writable by nginx
    
    # pagespeed FileCacheSizeKb          102400;
    # pagespeed FileCacheCleanIntervalMs 3600000;
    # pagespeed FileCacheInodeLimit      500000;
    
    #######################################################
    # Set it to 0 if you want to disable this feature.
    # pagespeed MessageBufferSize 100000;
    
    #######################################################
    # By default, ngx_pagespeed adds an X-PageSpeed header with a value of the version of
    # ngx_pagespeed being used. This directive lets you specify the value to use instead:
    # pagespeed XHeaderValue "ngx_pagespeed";
    
    #######################################################
    # let's speed up PageSpeed by storing it in the super duper fast memcached
    # Ensure Memcached server installed http://centminmod.com/memcached.html
    # default install for centmin mod is on port 11211, so localhost:11211 is correct
    # uncomment - remove hash # in front of below 2 lines to enable
    # timeout set at 100 milliseconds
      pagespeed MemcachedThreads 1;
      pagespeed MemcachedServers "localhost:11211";
      pagespeed MemcachedTimeoutUs 100000;
    
    #######################################################
    ## https://developers.google.com/speed/pagespeed/module/admin#virtual-hosts-and-stats
    ######################################
    # pagespeed UsePerVhostStatistics on;
    
    #######################################################
    ## 1.7.30.1 beta defaults
    ######################################
    pagespeed PreserveUrlRelativity on;
    pagespeed MaxCombinedCssBytes -1;
    pagespeed ImageResolutionLimitBytes 16777216;
    pagespeed EnableFilters inline_google_font_css;
    
    #######################################################
    ## 1.6.29.3 beta defaults
    ######################################
    pagespeed AvoidRenamingIntrospectiveJavascript on;
    pagespeed ImageInlineMaxBytes 3072;
    pagespeed CssImageInlineMaxBytes 0;
    #pagespeed MaxInlinedPreviewImagesIndex -1;
    #pagespeed MinImageSizeLowResolutionBytes 3072;
    
    #######################################################
    ## ngx_pagespeed filters settings below ##
    ######################################
    
      # show half the users an optimized site, half the regular site
      # change UA-XXXXXXXXXX-1 to your GA unique id
      # uncomment - remove hash # in front of below 5 lines to enable
    #  pagespeed RunExperiment on;
    #  pagespeed AnalyticsID UA-XXXXXXXXXX-1;
    #  pagespeed ExperimentVariable 1;
    #  pagespeed ExperimentSpec "id=1;percent=50;level=CoreFilters;enabled=collapse_whitespace,remove_comments;";
    #  pagespeed ExperimentSpec "id=2;percent=50";
    
      # Filter settings
      # https://developers.google.com/speed/pagespeed/module/filter-attribute-elide
       pagespeed EnableFilters elide_attributes;
    
      # https://developers.google.com/speed/pagespeed/module/filter-dedup-inlined-images
       pagespeed EnableFilters dedup_inlined_images;
    
      # filters outlined at http://ngxpagespeed.com/ngx_pagespeed_example/
      pagespeed RewriteLevel CoreFilters;
      pagespeed EnableFilters collapse_whitespace,remove_comments;
    
      # make_google_analytics_async
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-make-google-analytics-async
    #  pagespeed EnableFilters make_google_analytics_async;
    
      # prioritize_critical_css
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-prioritize-critical-css
       pagespeed EnableFilters prioritize_critical_css;
    
      # move_css_to_head
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-to-head
      pagespeed EnableFilters move_css_to_head;
    
      # move_css_above_scripts
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-above-scripts
      pagespeed EnableFilters move_css_above_scripts;
    
      # combine_css
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-combine
      pagespeed EnableFilters combine_css;
    
       # Uncomment this if you want to prevent mod_pagespeed from combining files
       # (e.g. CSS files) across paths
       #
    #  pagespeed CombineAcrossPaths off;
    
      # combine_javascript
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-js-combine
      pagespeed EnableFilters combine_javascript;
      pagespeed MaxCombinedJsBytes 140000;
      pagespeed EnableFilters defer_javascript;
    
      # extend_cache
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-cache-extend
    #  pagespeed EnableFilters extend_cache;
    
      # rewrite_css
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-rewrite
      pagespeed EnableFilters rewrite_css;
    
      # rewrite_javascript
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-js-minify
      pagespeed EnableFilters rewrite_javascript;
    
      # inline_javascript
      # https://developers.google.com/speed/pagespeed/module/filter-js-inline
      pagespeed EnableFilters inline_javascript;
    
      # inline_preview_images
      # https://developers.google.com/speed/pagespeed/module/filter-inline-preview-images
      pagespeed EnableFilters inline_preview_images;
    
      # resize_mobile_images
      # https://developers.google.com/speed/pagespeed/module/filter-inline-preview-images#resize_mobile_images
      pagespeed EnableFilters resize_mobile_images;
      pagespeed MaxInlinedPreviewImagesIndex 6;
      pagespeed MinImageSizeLowResolutionBytes 3072;
    
      # lazyload_images
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-lazyload-images
      pagespeed EnableFilters lazyload_images;
      pagespeed LazyloadImagesAfterOnload off;
    
      # rewrite_images
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-image-optimize
       pagespeed EnableFilters rewrite_images;
      #pagespeed DisableFilters rewrite_images;
      #pagespeed DisableFilters recompress_images;
      #pagespeed DisableFilters convert_png_to_jpeg;
      #pagespeed DisableFilters extend_cache_images;
      pagespeed EnableFilters convert_png_to_jpeg;
      pagespeed EnableFilters convert_jpeg_to_webp;
      pagespeed EnableFilters convert_to_webp_lossless;
    
      # sprite_images
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-image-sprite
    pagespeed EnableFilters rewrite_css,sprite_images;
    
      # Bound the number of images that can be rewritten at any one time; this
      # avoids overloading the CPU.  Set this to 0 to remove the bound.
      #
    #  pagespeed ImageMaxRewritesAtOnce 2;
    
      # insert_dns_prefetch
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-insert-dns-prefetch
    #  pagespeed EnableFilters insert_dns_prefetch;
    
      # InPlaceResourceOptimization
      # https://developers.google.com/speed/pagespeed/module/system#ipro
      # Enabled by default as of 1.9.32.1
      pagespeed InPlaceResourceOptimization off;
    #######################################################
    
    Note:

    If you're using https/SSL need additional settings which are not found in my forum's posted pagespeed.conf PageSpeed HTTPS Support - PageSpeed Module — Google Developers

    For example if I had https/SSL enabled on the forums I need to add to pagespeed.conf this line. Changing your paths appropriately for your domain of course.

    Code:
    pagespeed LoadFromFile "https://community.centminmod.com" "/home/nginx/domains/community.centminmod.com/public";
    Update: Feb 23, 2016

    Looks like a centmin mod user's question on ngx_pagespeed issue tracker at CSS, JS not combing & Images are not rewriting · Issue #1129 · pagespeed/ngx_pagespeed · GitHub has led to learning something new for me too

    instead of using LoadFromFile format like this which may incorrect try to optimise non-static files
    Code (Text):
    pagespeed LoadFromFile "http://centminmod.com" "/home/nginx/domains/centminmod.com/public";
    pagespeed LoadFromFile "https://centminmod.com" "/home/nginx/domains/centminmod.com/public";
    

    you can use format from LoadFromFileMatch and LoadFromFileRuleMatch to tell ngx_pagespeed to only optimise static files with specific extensions !
    Code (Text):
    pagespeed LoadFromFileMatch "^https?://centminmod.com/" "/home/nginx/domains/centminmod.com/public/";
    pagespeed LoadFromFileRuleMatch disallow .*;
    pagespeed LoadFromFileRuleMatch allow \.css$;
    pagespeed LoadFromFileRuleMatch allow \.jpe?g$;
    pagespeed LoadFromFileRuleMatch allow \.png$;
    pagespeed LoadFromFileRuleMatch allow \.gif$;
    pagespeed LoadFromFileRuleMatch allow \.js$;

    The first line matches both http and https version of site so only use if you have SSL certificate and https and http both working. If only have http site and NO https use
    Code (Text):
    pagespeed LoadFromFileMatch "^http://centminmod.com/" "/home/nginx/domains/centminmod.com/public/";
    pagespeed LoadFromFileRuleMatch disallow .*;
    pagespeed LoadFromFileRuleMatch allow \.css$;
    pagespeed LoadFromFileRuleMatch allow \.jpe?g$;
    pagespeed LoadFromFileRuleMatch allow \.png$;
    pagespeed LoadFromFileRuleMatch allow \.gif$;
    pagespeed LoadFromFileRuleMatch allow \.js$;
    

    or just old LoadFromFile
    Code (Text):
    pagespeed LoadFromFile "http://centminmod.com" "/home/nginx/domains/centminmod.com/public";
    pagespeed LoadFromFileRuleMatch disallow .*;
    pagespeed LoadFromFileRuleMatch allow \.css$;
    pagespeed LoadFromFileRuleMatch allow \.jpe?g$;
    pagespeed LoadFromFileRuleMatch allow \.png$;
    pagespeed LoadFromFileRuleMatch allow \.gif$;
    pagespeed LoadFromFileRuleMatch allow \.js$;
    
     
    Last edited: Apr 10, 2017
    • Like Like x 6
    • Useful Useful x 2
  2. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    The Disallow directives are to work around some Nginx Pagespeed incompatible Xenforo elements such as json requests like

    Code:
    pagespeed Disallow */js/dark/postrating.js*;
    pagespeed Disallow */js/xenforo/tabalerts.js*;
    pagespeed Disallow */lost-password/lost;
    pagespeed Disallow */lost-password/*;
    pagespeed Disallow */payment_callback.php*;
    pagespeed Disallow */munin/*;
    pagespeed Disallow */admincp/*;
    pagespeed Disallow */cron.php*;
    pagespeed Disallow */admin.php*;
    pagespeed Disallow */css.php*;
    pagespeed Disallow */js/jquery/jquery-1.11.0.min.js*;
    pagespeed Disallow */js/xenforo/xenforo.js*;
    pagespeed Disallow */mark-read*;
    pagespeed Disallow */forums/-/mark-read*;
    pagespeed Disallow */reply/preview*;
    pagespeed Disallow */account/alerts-popup*;
    pagespeed Disallow */conversations/popup*;
    pagespeed Disallow */conversations/*;
    pagespeed Disallow */account/alerts/*;
    pagespeed Disallow */?card*;
    pagespeed Disallow */misc/quick-navigation-menu*;
    pagespeed Disallow */misc/update-cache-ttl*;
    pagespeed Disallow */deferred.php*;
    pagespeed Disallow */forums/*;
    pagespeed Disallow */attachments/*;
    pagespeed Disallow */rgba.php*;
    pagespeed Disallow */add-reply*;
    pagespeed Disallow */edit-inline*;
    pagespeed Disallow */save-inline*;
    pagespeed Disallow */posts/*/save-inline*;
    pagespeed Disallow */posts/*/edit*;
    pagespeed Disallow */posts/*/delete*;
    pagespeed Disallow */posts/*/ip*;
    pagespeed Disallow */posts/*/report*;
    pagespeed Disallow */proxy.php*;
    
     
    Last edited: May 28, 2015
    • Like Like x 1
  3. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    FYI, cron.php is not a Xenforo Core file anymore.
    I think it's just a XenForo 1.1.x file not for XF 1.2.x+
     
    • Like Like x 1
  4. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    Cleaned up and revised my pagespeed.conf to the one above.
     
  6. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    Any reason you dis allow this?
    Code:
    pagespeed Disallow */js/jquery/jquery-1.11.0.min.js*;
    pagespeed Disallow */js/xenforo/xenforo.js*;
     
  7. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    To prevent pagespeed from deferring them as they can break stuff that requires them early on depending on the style etc.
     
    • Like Like x 2
  8. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    I still encounter a broken style when bdcache css are combine or embed directly to the page.
    Right now all the bdcache css are set to disallow on my forum to fix some style issue.
     
  9. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    could be style specific ?
     
  10. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    Maybe, sometimes login overlay didn't display correctly.
     
  11. BamaStangGuy

    BamaStangGuy Active Member

    462
    136
    43
    May 25, 2014
    Ratings:
    +179
    Local Time:
    12:29 PM
    So if you don't defer js with pagespeed then it should be fine?
     
  12. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah should be, although would defeat a huge purpose of using pagespeed for other js files if pagespeed didn't enable defer js filter (with Disallow exclusions where necessary) :)
     
  13. BamaStangGuy

    BamaStangGuy Active Member

    462
    136
    43
    May 25, 2014
    Ratings:
    +179
    Local Time:
    12:29 PM
    Defer JS screws up my advertising unfortunately.
     
  14. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  15. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
  16. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    Added a few more Xenforo specific pagespeed filter exclusions, when editing a post, the editor lags when loading due to pagespeed deferring js files. So disabling these allow the editor to render immediately rather than deferred :D

    Code:
    pagespeed Disallow */edit-inline*;
    pagespeed Disallow */save-inline*;
    pagespeed Disallow */posts/*/save-inline*;
    pagespeed Disallow */posts/*/edit*;
    pagespeed Disallow */posts/*/delete*;
    pagespeed Disallow */posts/*/ip*;
    pagespeed Disallow */posts/*/report*;
    
     
    • Like Like x 1
  17. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    Is the config on 1st post updated with the one your using now on https ?
     
    • Like Like x 1
  18. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    it is now :)
     
    • Like Like x 1
  19. RoldanLT

    RoldanLT Well-Known Member

    3,788
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    1:29 AM
    1.11
    10.2
    Your not using pagespeed FetchHttps enable; ?
     
  20. eva2000

    eva2000 Administrator Staff Member

    27,784
    6,337
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,340
    Local Time:
    3:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1