Join the community today
Become a Member

Nginx Nginx - ngx_brotli

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by bassie, Jun 5, 2016.

  1. bassie

    bassie Active Member

    491
    103
    43
    Apr 29, 2016
    Ratings:
    +310
    Local Time:
    5:17 PM
    Someone using ngx_brotli ?
    brotli_min_length .... - the minimal size of the resource to be compressed.
    Brotli will compress only resources larger than this value.

    If it is smaller it will let gzip to compress.

    Apparently this variable seems to be ignored in my case.
    Everything is compressed by Brotli.

    The ngx_brotli module seems a bit unstable but I'm curious about your experiences.
    Maybe it's something else (bug, my mistake, page speed,FastCGI etc) hence this topic.

    What is your experience with brotli and Nginx?

    Thanks,
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    which version of CentOS 6 or 7 ? which web browser and browser version ? tried firefox 45+ and google canary ?

    are using centmin mod 123.09beta01 with persistent config set for
    Code (Text):
    NGINX_LIBBROTLI=y

    ?

    ensure /usr/local/nginx/conf/nginx.conf has include file
    Code (Text):
    include /usr/local/nginx/conf/brotli_inc.conf;

    with content for brotli options
    Code (Text):
    brotli on;
    brotli_static on;
    brotli_min_length 1000;
    brotli_buffers 32 8k;
    brotli_comp_level 5;
    brotli_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;

    what's output in ssh for https version of yourdomain.com/path/toteststaticfile which is less than brotli_min_length
    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" https://yourdomain.com/path/toteststaticfile | egrep 'Content-Encoding|^Content-Type|Content-Length'

    i.e. for https version of centminmod.com
    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" https://centminmod.com | egrep 'Content-Encoding|^Content-Type|Content-Length'
    Content-Type: text/html; charset=utf-8
    Content-Encoding: br
    

    also output for
    Code (Text):
    nginx -V


    for me brotli_min_length works fine 123.09beta01 + nginx 1.11.1 + ngx_pagespeed 1.11.33.2 beta
     
    Last edited: Jun 5, 2016
  3. bassie

    bassie Active Member

    491
    103
    43
    Apr 29, 2016
    Ratings:
    +310
    Local Time:
    5:17 PM
    Yep. All the the above settings are used correctly.
    Found that there was a hardware failure, which caused the problem.
    I am terribly sorry. But this is beyond my reach.
     
  4. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    hardware failure ? vps problems ?
     
  5. bassie

    bassie Active Member

    491
    103
    43
    Apr 29, 2016
    Ratings:
    +310
    Local Time:
    5:17 PM
    Physical hardware problems.
     
    • Informative Informative x 1
  6. bassie

    bassie Active Member

    491
    103
    43
    Apr 29, 2016
    Ratings:
    +310
    Local Time:
    5:17 PM
    Its almost a shame that I asked a question while it appears later, to be a hardware problem.
    But that is the world of electronic technology.
    If something is almost broken you often get unexplainable problems.
    So again sorry. my apologies.
     
  7. RoldanLT

    RoldanLT Well-Known Member

    3,821
    927
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,255
    Local Time:
    11:17 PM
    1.11
    10.2
  8. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    not able to reproduce your problem here

    did you custom disable some nginx modules via persistent /etc/centminmod/custom_config.inc ? tried using default Centmin Mod set of nginx modules instead ?

    works fine on this forum for brotli content-encoding = br

    Code (Text):
    curl -vso /dev/null -H"Accept-Encoding: gzip, br" https://community.centminmod.com/
    *   Trying 192.124.249.60...
    * Connected to community.centminmod.com (192.124.249.60) port 443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/certs/ca-certificates.crt
      CApath: none
    * TLSv1.2 (OUT), TLS header, Certificate Status (22):
    } [5 bytes data]
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    } [512 bytes data]
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    { [107 bytes data]
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    { [4334 bytes data]
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    { [333 bytes data]
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    { [4 bytes data]
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    } [70 bytes data]
    * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
    } [1 bytes data]
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    } [16 bytes data]
    * TLSv1.2 (IN), TLS change cipher, Client hello (1):
    { [1 bytes data]
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    { [16 bytes data]
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    * ALPN, server accepted to use h2
    * Server certificate:
    *  subject: OU=Domain Control Validated; OU=GGSSL Wildcard SSL; CN=*.centminmod.com
    *  start date: Aug 14 00:00:00 2014 GMT
    *  expire date: Aug 13 23:59:59 2017 GMT
    *  subjectAltName: host "community.centminmod.com" matched cert's "*.centminmod.com"
    *  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
    *  SSL certificate verify ok.
    * Using HTTP2, server supports multi-use
    * Connection state changed (HTTP/2 confirmed)
    * TCP_NODELAY set
    * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
    } [5 bytes data]
    * Using Stream ID: 1 (easy handle 0x1b19d30)
    } [5 bytes data]
    > GET / HTTP/1.1
    > Host: community.centminmod.com
    > User-Agent: curl/7.50.1-DEV
    > Accept: */*
    > Accept-Encoding: gzip, br
    >
    { [5 bytes data]
    * Connection state changed (MAX_CONCURRENT_STREAMS updated)!
    } [5 bytes data]
    < HTTP/2 200
    < server: nginx
    < date: Sun, 14 Aug 2016 14:52:36 GMT
    < content-type: text/html; charset=UTF-8
    < vary: Accept-Encoding
    < set-cookie: xf_session=ec7a4be4bda98e02b6ff8fc973251b5e; path=/; secure; httponly
    < x-frame-options: SAMEORIGIN
    < public-key-pins: pin-sha256="oGbPgwR7vxLMpWdDIy+gc/Z0YD0EYCblHDCCgNQg9W8="; pin-sha256="KrRz+515ViRd/gdl7yGWCW1R4CFAAeMIBHp0JTNk8qc="; max-age=900; report-uri="https://cmcommunity.report-uri.io/r/default/hpkp/reportOnly"
    < strict-transport-security: max-age=31536000; includeSubdomains
    < x-page-speed: CentminMod PageSpeed
    < cache-control: max-age=0, no-cache
    < content-encoding: br
    < x-sucuri-id: 11010
    <
    { [7289 bytes data]
    * Connection #0 to host community.centminmod.com left intact
     
    • Like Like x 1
  9. RoldanLT

    RoldanLT Well-Known Member

    3,821
    927
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,255
    Local Time:
    11:17 PM
    1.11
    10.2
    Yes, I always have.
     
  10. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    So you have some servers/web apps working with brotli and some not ? or all not working ?
     
  11. RoldanLT

    RoldanLT Well-Known Member

    3,821
    927
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,255
    Local Time:
    11:17 PM
    1.11
    10.2
    Only one is not behind Cloudflare, so others don't have brotli.
    I only got this single site with Brotli :).
     
  12. RoldanLT

    RoldanLT Well-Known Member

    3,821
    927
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,255
    Local Time:
    11:17 PM
    1.11
    10.2
    I will try soon resetting all the modules to default and try what modules cause it.
     
  13. BobbyWibowo

    BobbyWibowo Active Member

    166
    36
    28
    Jul 30, 2015
    Medan, Indonesia
    Ratings:
    +57
    Local Time:
    10:17 PM
    If I use CloudFlare, I assume there's no use to enable the module for the time being, right? I mean, brotli compression will only be used during transaction between my server and CloudFlare (I assume, I still need confirmation), while CloudFlare will use their own compression to the client (I believe they're still using gzip. I read their blog recently and they said that they are still not quite convinced of the advantage of using brotli compared to gzip or something along that line).
     
  14. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    yup no use
     
    • Like Like x 1
  15. bassie

    bassie Active Member

    491
    103
    43
    Apr 29, 2016
    Ratings:
    +310
    Local Time:
    5:17 PM
    • Informative Informative x 1
  16. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    let's test it then, enable brotli nginx module via persistent config file /etc/centminmod/custom_config.inc
    Code (Text):
    NGXDYNAMIC_BROTLI=y
    NGINX_LIBBROTLI=y

    and recompile nginx via centmin.sh menu option 4

    compiled ok
    dynamically compiled nginx modules at /usr/local/nginx/modules
    Code (Text):
    -rwxr-xr-x  1 root root 124K Aug 21 04:45 ngx_http_brotli_filter_module.so
    -rwxr-xr-x  1 root root 114K Aug 21 04:45 ngx_http_brotli_static_module.so
    -rwxr-xr-x  1 root root 141K Aug 21 04:45 ngx_http_fancyindex_module.so
    -rwxr-xr-x  1 root root 141K Aug 21 02:01 ngx_http_fancyindex_module.so.old
    -rwxr-xr-x  1 root root 140K Aug 21 04:45 ngx_http_image_filter_module.so
    -rwxr-xr-x  1 root root 140K Aug 21 02:01 ngx_http_image_filter_module.so.old
    -rwxr-xr-x  1 root root 927K Aug 21 04:45 ngx_stream_module.so
    -rwxr-xr-x  1 root root 927K Aug 21 02:01 ngx_stream_module.so.old

    Code (Text):
    cat /usr/local/nginx/conf/dynamic-modules.conf
    load_module "modules/ngx_http_brotli_filter_module.so";
    load_module "modules/ngx_http_brotli_static_module.so";
    load_module "modules/ngx_http_image_filter_module.so";
    load_module "modules/ngx_http_fancyindex_module.so";
    load_module "modules/ngx_stream_module.so";


    Test localhost via curl (replace localhost with your site domain name if you want)

    before ngx_brotli module enabling = gzip content-encoding
    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" localhost | egrep 'Content-Encoding|^Content-Type|Content-Length'                    
    Content-Type: text/html; charset=utf-8
    Content-Encoding: gzip

    after ngx_brotli module enabling = br content-encoding
    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" localhost | egrep 'Content-Encoding|^Content-Type|Content-Length'                     
    Content-Type: text/html; charset=utf-8
    Content-Encoding: br
     
  17. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  18. RoldanLT

    RoldanLT Well-Known Member

    3,821
    927
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,255
    Local Time:
    11:17 PM
    1.11
    10.2
    • Informative Informative x 2
  19. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    strange indeed - at least we know why now
     
    • Like Like x 1
  20. eva2000

    eva2000 Administrator Staff Member

    28,923
    6,565
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,742
    Local Time:
    1:17 AM
    Nginx 1.13.x
    MariaDB 5.5
    @RoldanLT on the affected server what's output for
    Code (Text):
    php -i | egrep '^output|zlib.output'

    i.e.
    Code (Text):
    php -i | egrep '^output|zlib.output'
    output_buffering => 0 => 0
    output_encoding => no value => no value
    output_handler => no value => no value
    zlib.output_compression => Off => Off
    zlib.output_compression_level => -1 => -1
    zlib.output_handler => no value => no value