Get the most out of your Centmin Mod LEMP stack
Become a Member

Nginx PageSpeed Nginx Pagespeed image conversion outputs 404 errors (randomly)

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Simon Brown, Apr 3, 2017.

  1. Simon Brown

    Simon Brown Premium Member Premium Member

    20
    2
    3
    Feb 9, 2017
    Ratings:
    +4
    Local Time:
    1:50 AM
    1.11.9
    Hello All,
    Firstly, sorry if this is posted in the wrong place. I did look around but could find a better place to post.

    As the title suggests, I'm using Pagespeed to convert/optimise images on the fly.
    The issue I'm having is that about 75% of the time the images URL Pagespeed creates are don't link to files so I get a 404 error.

    The thing is, sometimes they do work!... After restarting services (nprestart) the images don't work again.

    I'm experiencing the same issue on 3 servers all created with fresh installs of Centos 7 then centmin installed on them.

    If I were to guess then I'd say that it's a permissions issue with Pagespeed unable to write the cache files but I have no idea how to test for this.
    • Has anyone else experienced the same issue?
    • Does anyone have any suggestions?
    • I've disabled rewrite_images so not sure why I'm still getting the 404 errors.
    It's a strong feature of Pagespeed which I really don't want to turn off if there's a fix :)

    I've attached 3 images.
    1x An example page and source code
    1x Pagespeed URL
    1x Original file so you can see it exists :)

    VHOST:
    Code:
    # 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;
    
    File: /usr/local/nginx/conf/pagespeed.conf
    Code:
     
    pagespeed on;
    
    #######################################################
    # 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;
    
    #######################################################
    ## 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;
    
      # 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;
    
     # 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;
    
      # 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 on;
    
    Screen Shot 2017-04-03 at 12.58.26 pm.png Screen Shot 2017-04-03 at 12.58.50 pm.png Screen Shot 2017-04-03 at 12.58.26 pm.png Screen Shot 2017-04-03 at 12.58.50 pm.png
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed:1.11.10
    • PHP Version Installed:7.0.15
    • MariaDB MySQL Version Installed:10.1.21
    • When was last time updated Centmin Mod code base ? : yesterday :)
    • Persistent Config:
    NGXDYNAMIC_NGXPAGESPEED='n'
    NGINX_PAGESPEED='y'
    NGXDYNAMIC_BROTLI=y
    NGINX_LIBBROTLI=y
    LETSENCRYPT_DETECT='y'
     

    Attached Files:

  2. eva2000

    eva2000 Administrator Staff Member

    30,170
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,138
    Local Time:
    10:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    As per ngx_pagespeed page outlined at here, you need to uncomment all 3 lines in nginx vhost
    Code (Text):
    # 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;
    

    you had 3rd line commented out though that should cause 404 not found for images

    once ngx_pagespeed is compiled into nginx, you can use pscontrol command to turn it on and off globally on nginx server

    if you turn off ngx_pagespeed via command
    Code (Text):
    pscontrol off
    

    does it work ?
    if you turn back ngx_pagespeed via command
    Code (Text):
    pscontrol on
    



    You'd have to troubleshoot and tweak it yourself following these guides and info outlined below
     
    • Informative Informative x 1