Welcome to Centmin Mod Community
Become a Member

Nginx PageSpeed ngx_pagespeed doesn't seem to work

Discussion in 'Install & Upgrades or Pre-Install Questions' started by Fernando, Apr 27, 2019.

  1. Fernando

    Fernando Member

    67
    12
    8
    Jul 21, 2017
    Ratings:
    +23
    Local Time:
    2:50 AM
    1.13.3
    10.1.25
    Please fill in any relevant information that applies to you:
    • CentOS Version: CentOS 7.6 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: 1.15.12
    • PHP Version Installed: PHP v7.3.4
    • MariaDB MySQL Version Installed:10.1.34-MariaDB
    • When was last time updated Centmin Mod code base ? : Today
    • Persistent Config: Do you have any persistent config file options set in /etc/centminmod/custom_config.inc ? You can check via this command:
      Code (Text):
      MARCH_TARGETNATIVE='n'
      LETSENCRYPT_DETECT='y'
      DUALCERTS='y'
      NGXDYNAMIC_NGXPAGESPEED='y'
      NGINX_PAGESPEED='y'
      

    Hi, I'm trying to configure ngx_pagespeed but it seems it's not working properly. I have a WordPress Multisite I can confirm everything works perfectly.

    Domain: zonamotriz.com
    Subdomain: dev.zonamotriz.com

    I have followed: https://centminmod.com/nginx_ngx_pagespeed.html#howtoinstall

    When I go to

    https://zonamotriz.com/pagespeed_global_admin

    I see data, however, going to Message history I don't see specific images to be
    rewrite from my own domain.

    Also, If I test my domain and subdomain here: https://ismodpagespeedworking.com/ I don't see the headers:

    If I checked in Developer console I don't see anything modified, so I really don't know if I'm missing something.

    If I go to https://zonamotriz.com/pagespeed_global_admin/cache#show_metadata

    And put the main URL I got:
    Metadata cache key:rname/aj_172HbbQelV1hdAyX7NAZ/http://zonamotriz.com/@@_
    cache_ok:false
    can_revalidate:false
    partitions:

    Not sure if it's normal or not. I have recompile twice nginx and doubled check everything but not sure what else to check.

    Code:
    [19:24][[email protected] conf.d]# cat zonamotriz.com.ssl.conf
    
    #x# HTTPS-DEFAULT
    map $http_host $blogid {
        default       -999;
                    include /home/nginx/domains/zonamotriz.com/public/wp-content/uploads/nginx-helper/map.conf;
    }
    
     server {
    
       server_name zonamotriz.com *.zonamotriz.com;
       return 302 https://$host$request_uri;
       include /usr/local/nginx/conf/staticfiles.conf;
     }
    
    server {
      listen 443 ssl http2 reuseport;
      server_name zonamotriz.com *.zonamotriz.com;
    
      include /usr/local/nginx/conf/ssl/zonamotriz.com/zonamotriz.com.crt.key.conf;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/zonamotriz.com/origin.crt;
      #ssl_verify_client on;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      # mozilla recommended
      ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
    
      # enable ocsp stapling
      resolver 8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1 valid=10m;
      resolver_timeout 10s;
      ssl_stapling on;
      ssl_stapling_verify on;
    
    # ngx_pagespeed & ngx_pagespeed handler
    include /usr/local/nginx/conf/pagespeed.conf;
    include /usr/local/nginx/conf/pagespeedhandler.conf;
    include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/zonamotriz.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/zonamotriz.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/zonamotriz.com/autoprotect-zonamotriz.com.conf;
      root /home/nginx/domains/zonamotriz.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      #include /usr/local/nginx/conf/wpincludes/zonamotriz.com/wpcacheenabler_zonamotriz.com.conf;
      #include /usr/local/nginx/conf/wpincludes/zonamotriz.com/wpsupercache_zonamotriz.com.conf;
      # https://community.centminmod.com/posts/18828/
      include /usr/local/nginx/conf/wpincludes/zonamotriz.com/rediscache_zonamotriz.com.conf;
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      #try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      try_files $uri $uri/ /index.php?$args;
    
      }
    
      # Rewrites for subdomains
      rewrite /wp-admin$ $scheme://$host$uri/ permanent;
      #rewrite ^/(wp-.*)$ /wordpress/$1 last;
      #rewrite ^/(/.*\.php) /wordpress$1 last;
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        auth_basic "Private";
        auth_basic_user_file /home/nginx/domains/zonamotriz.com/htpasswd_wplogin;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
    location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        # https://community.centminmod.com/posts/18828/
        include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
      include /usr/local/nginx/conf/wpincludes/zonamotriz.com/wpsecure_zonamotriz.com.conf;
      #include /usr/local/nginx/conf/php-wpsc.conf;
    
      # https://community.centminmod.com/posts/18828/
      include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-zonamotriz.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    Pagespeed.conf

    Code:
    [19:33][[email protected] conf.d]# cat /usr/local/nginx/conf/pagespeed.conf
    pagespeed on;
    
    ####### My Settings #######
    pagespeed RedisServer "127.0.0.1:6379";
    pagespeed RedisDatabaseIndex 7;
    pagespeed Domain *.zonamotriz.com;
    ######  End My Setting #####
    
    
    #######################################################
    # Purge nginx pagespeed cache
    # https://developers.google.com/speed/pagespeed/module/system#flush_cache
    #######################################################
    pagespeed EnableCachePurge on;
    pagespeed PurgeMethod PURGE;
    
    ########################################################
    # File cache settings
    ######################################
    # needs to exist and be writable by nginx
    
    # pagespeed FileCacheSizeKb          102400;
    # pagespeed FileCacheCleanIntervalMs 3600000;
    # pagespeed FileCacheInodeLimit      500000;
    
    #######################################################
    # 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;
    
    #######################################################
    ## 1.11.33.0 beta save-data
    ######################################
    # https://developers.google.com/speed/pagespeed/module/filter-image-optimize#image-quality
    
    # https://developers.google.com/speed/pagespeed/module/reference-image-optimize#JpegQualityForSaveData
    pagespeed JpegQualityForSaveData 50;
    
    # https://developers.google.com/speed/pagespeed/module/reference-image-optimize#WebpQualityForSaveData
    pagespeed WebpQualityForSaveData 50;
    
    # https://developers.google.com/speed/pagespeed/module/filter-image-optimize#resize_rendered_image_dimensions
    pagespeed EnableFilters resize_rendered_image_dimensions;
    
    # https://developers.google.com/speed/pagespeed/module/filter-image-optimize#WebpRecompressionQuality
    pagespeed WebpRecompressionQuality 75;
    
    #######################################################
    ## 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
      # filters outlined at http://ngxpagespeed.com/ngx_pagespeed_example/
      pagespeed RewriteLevel CoreFilters;
      pagespeed EnableFilters collapse_whitespace,remove_comments;
    
      # https://www.modpagespeed.com/doc/config_filters#FinderPropertiesCacheExpirationTimeMs
    #  pagespeed FinderPropertiesCacheExpirationTimeMs 7200000;
    
      # https://www.modpagespeed.com/doc/config_filters#forbidding
       pagespeed ForbidAllDisabledFilters true;
    
      # 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;
    
      # make_google_analytics_async
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-make-google-analytics-async
    #  pagespeed EnableFilters make_google_analytics_async;
    
      # make_show_ads_async
      # https://developers.google.com/speed/pagespeed/module/filter-make-show-ads-async
    #  pagespeed EnableFilters make_show_ads_async;
    
      # responsive_images, responsive_images_zoom
      # https://developers.google.com/speed/pagespeed/module/filter-image-responsive
    #  pagespeed EnableFilters responsive_images;
    #  pagespeed EnableFilters responsive_images_zoom;
    
      # convert_to_webp_animated
      # https://developers.google.com/speed/pagespeed/module/filter-image-optimize#convert_to_webp_animated
    #  pagespeed EnableFilters convert_to_webp_animated;
    
      # inline_google_font_css
      # https://developers.google.com/speed/pagespeed/module/filter-css-inline-google-fonts
      pagespeed EnableFilters inline_google_font_css;
    
      # require FetchHttps if using https site
    #   pagespeed FetchHttps enable;
    
      # https://www.modpagespeed.com/doc/https_support
        pagespeed SslCertDirectory /etc/pki/tls/certs;
        pagespeed SslCertFile /etc/pki/tls/cert.pem;
    
      # inline_css
      # https://developers.google.com/speed/pagespeed/module/filter-css-inline
    #   pagespeed EnableFilters inline_css;
    #   pagespeed CssInlineMaxBytes 2048;
    
      # 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 122900;
    
      # 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_preview_images
      # https://developers.google.com/speed/pagespeed/module/filter-inline-preview-images
      pagespeed EnableFilters inline_preview_images;
    
      # lazyload_images
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-lazyload-images
    #  pagespeed EnableFilters lazyload_images;
    
      # 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;
    
      # 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;
    
    #######################################################
    Thank you,
    Best Regards
     
  2. eva2000

    eva2000 Administrator Staff Member

    41,386
    9,297
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,261
    Local Time:
    6:50 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    ngx_pagespeed doesn't immediate optimise assets, it takes many page loads for ngx_pagespeed to learn the page's makeup/layout and what assets can be optimised and will only optimise if it's of benefit. So if an optimised image or asset is larger than the original, ngx_pagespeed will skip optimisation. It should show up in the ngx_pagespeed admin console message history logs if it does.

    one thing try using memcached cache instead of redis cache with ngx_pagespeed as redis is newer and may not be 100%.
    Code (Text):
      pagespeed MemcachedThreads 1;
      pagespeed MemcachedServers "localhost:11211";
      pagespeed MemcachedTimeoutUs 100000;
    


    I assume you have uncommented/enabled the message directive in /usr/local/nginx/conf/pagespeedadmin.conf (can edit using nano via cmd shortcut = pscontrol admin)
    Code (Text):
     pagespeed MessageBufferSize 100000;
    


    You'd have to troubleshoot and tweak it yourself following these guides and info outlined below
     
    • Like Like x 1
  3. Fernando

    Fernando Member

    67
    12
    8
    Jul 21, 2017
    Ratings:
    +23
    Local Time:
    2:50 AM
    1.13.3
    10.1.25
    Hi Eva,

    Thank you. I did the following changes and now it's working fine.

    I noticed the following in: /usr/local/nginx/conf/pagespeed.conf
    I didn't have the following option:
    pagespeed FileCachePath /var/ngx_pagespeed_cache;

    Additionally I changed the Domain from:
    pagespeed Domain *.zonamotriz.com; to
    pagespeed Domain https://*.zonamotriz.com;

    So now it looks like this:
    Finally, I did the same changes using:
    pscontrol admin

    Thank you,
    Best Regards
     
  4. eva2000

    eva2000 Administrator Staff Member

    41,386
    9,297
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,261
    Local Time:
    6:50 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Glad to hear
    that is set in /usr/local/nginx/conf/pagespeedadmin.conf ;)

    that's probably what made it work
    no need to repeat pagespeed Domain entries in /usr/local/nginx/conf/pagespeedadmin.conf
     
    • Useful Useful x 1
  5. Fernando

    Fernando Member

    67
    12
    8
    Jul 21, 2017
    Ratings:
    +23
    Local Time:
    2:50 AM
    1.13.3
    10.1.25
    Hi Eva,

    Excellent, its clear now :) thank you for all your sugestions :)