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

Sysadmin How to resizing image with nginx

Discussion in 'System Administration' started by hendry, Oct 11, 2016.

  1. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    strange Just in time compiler support is reported as enabled

    try centmin.sh menu option 4 recompile again

    To troubleshoot nginx upgrade/recompile installation, you need to check the nginx upgrade log at /root/centminlogs and share via Pastebin.com or Gists he contents of the initial install log.

    This command will list logs in ascending time order so newest is at bottom
    Code (Text):
    ls -lahrt /root/centminlogs
     
  2. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    true but for web app like a forum with user provided images uploaded and/or embedded into posts remotely ?

    you can fine tune that too though somewhat
     
  3. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Last edited: Oct 12, 2016
  4. buik

    buik “Winners never quit, and quitters never win.” Premium Member

    1,293
    348
    83
    Apr 29, 2016
    Ratings:
    +1,051
    Local Time:
    4:06 PM
    Google is using a homemade solution to optimize images and pictures being uploaded by the system or users of course.

    For yourself as server admin.
    You can use a cronjob and script to optimize images i.e. in the images directory every few days.
    With optipng, jpeg and util-linux.

    For the best result, less server load, (LEMP) no unnecessary software, code and or plugins.
    On the most stable environment. (The more code, program and configuration, the more debugging at fault e.g. downtime.)
     
    Last edited: Oct 12, 2016
  5. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    9:06 PM
    nginx/1.11.4
    MariaDB 10
    I have try to recompile nginx also jit but still not work. I though this bug from jit. So i need to reinstall my vps and centminmod again :sick:
     
  6. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    well users will have to decide whether it's worth it or not :)
     
  7. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    no do not reinstall vps and centmin mod

    To troubleshoot, you need to check the the nginx upgrade log at /root/centminlogs and instructions under Sharing logs and errors heading for using Pastebin.com or Gists to share a sanitised version of the contents of the initial install log. You can see full details at How to troubleshoot Centmin Mod initial install issues

    also what's output of
    Code (Text):
    nginx -t

    when you run centmin.sh menu option 4 there's a nginx upgrade log timestamped at /root/centminlogs

    if you type this command it lists all logs in date ascending order so latest log at bottom
    Code (Text):
    ls -lArt /root/centminlogs

    so copy the entire contents of latest nginx_upgrade log to gist.github.com or pastebin.com
     
  8. buik

    buik “Winners never quit, and quitters never win.” Premium Member

    1,293
    348
    83
    Apr 29, 2016
    Ratings:
    +1,051
    Local Time:
    4:06 PM
    Of course always.
     
  9. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  10. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    9:06 PM
    nginx/1.11.4
    MariaDB 10
    Wow pagespeed increase the result so I want to share my experience here:

    I was asking about resizing image How to resizing image with nginx | Centmin Mod Community and @eva2000 advice me to use nginx pagespeed and here are the result.

    This is my first config:

    Code (Text):
    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 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;
    
      # 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;
    
      # 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;
      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_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;
    
      # 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;
    


    And the result from GTmetric:
    gtmetric result with pagespeed comment out header.png

    As you can see, above config and image showing advantage using pagespeed than my first post here.

    For second test I use the same config but disable/hashtag again this two line
    Code (Text):
     # pagespeed EnableFilters move_css_to_head;
     # pagespeed EnableFilters move_css_above_scripts;


    And the result is:
    gtmetric result with pagespeed.png

    Second test blasting my score from the first test and have significant result when I don't use pagespeed.

    Ok thats all from me, hope this useful for you and great thanks to @eva2000

    PS: The result may vary for you.
     
  11. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    pagespeed needs multiple page loads for it to monitor and analyse what can be optimised before optimising it, so variance between runs is normal.
     
  12. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    9:06 PM
    nginx/1.11.4
    MariaDB 10
    I agree because above test is using laravel, I'll test again using WP.

    Anyway, why I can't access mydomain/pagespeed_console, /ngx_pagespeed_statistics? I have enable pagespeed MessageBufferSize 100000 and add my IPs on handler. It's show 403 forbidden page. any suggest?
     
  13. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    9:06 PM
    nginx/1.11.4
    MariaDB 10
    Sorry it's work when I use hosting IPs but with this message:
    Code:
    Failed to load PageSpeed Console because:
    StatisticsLogging is not enabled.
    LogDir is not set.
    where I can set it?
     
  14. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    are you accessing stats from yourhostname.domain.com/pagespeed_global_admin/ ?

    did you set the ip to allow to your isp ip address ?

    it should already be set in /usr/local/nginx/conf/pagespeedstatslog.conf include file did you follow step 2 at Nginx PageSpeed - CentminMod.com LEMP Nginx web stack for CentOS

     
  15. pamamolf

    pamamolf Premium Member Premium Member

    3,815
    370
    83
    May 31, 2014
    Ratings:
    +712
    Local Time:
    5:06 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    It will be great if anyone has any related pagespeed rules for Invision forum :)
     
  16. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    9:06 PM
    nginx/1.11.4
    MariaDB 10
    Sry it was my mistake, I access it from mydomain.com not hostname. :smuggrin:
     
  17. pamamolf

    pamamolf Premium Member Premium Member

    3,815
    370
    83
    May 31, 2014
    Ratings:
    +712
    Local Time:
    5:06 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    How can i set a rule for pagespeed so i can get optimized images from users posts linking images from tinypic.com for example?

    :)
     
  18. eva2000

    eva2000 Administrator Staff Member

    44,693
    10,193
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,794
    Local Time:
    12:06 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    by default you can't it's only for images hosted on your server or domain (i.e. cdn) so only trusted domain/hostnames. You could allow tinypic but i wouldn't it's for trusted domains only like your own hosted. It's a security issue.