Join the community today
Become a Member

Featured Nginx How to use Brotli compression for Centmin Mod Nginx web servers

Discussion in 'Centmin Mod User Tutorials & Guides' started by eva2000, Mar 6, 2017.

  1. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    If you're using Cloudflare in front of your server, then KeyCDN is testing brotli checks against Cloudflare server and not Centmin Mod Nginx. Cloudflare has their own dashboard setting to enable Brotli under Speed settings What will Cloudflare compress?
     
  2. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    i have enable brotli option in cloudflare.

    Chrome is also showing gzip check yourself site link is wpseo.ml
     
    Last edited: May 12, 2018
  3. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    if you have wordpress plugins which auto compress/gzip wp files then that takes priority over nginx level brotli compression. You need to turn off all wordpress plugins' settings which deal with auto compression/gzipping.
     
  4. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Done. Disabled autoptimize plugin. Restarted nginx. Still not showing brotli

    Do i have to check the Auto Minify (CSS, JS, HTML) in cloudflare to checked or unchecked?
     
  5. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    restart nginx + php-fpm using command shortcut
    Code (Text):
    nprestart
    
     
  6. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Tried still gzip compression. Can't find whats going wrong here.. :banghead:
     
  7. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    what's output for commands wrap in CODE tags
    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" https://yourdomain.com
    

    Code (Text):
    curl -sI /dev/null -H"Accept-Encoding: gzip,br" http://yourdomain.com
    

    checking the Content-Encoding: line to see if it shows gzip or br
     
  8. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Here's the output for https command:
    Code:
    HTTP/1.1 200 OK
    Date: Sat, 12 May 2018 17:09:04 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Set-Cookie: __cfduid=dfb4e0b1f39887ccf8b810c273a6cd7221526144943; expires=Sun, 12-May-19 17:09:03 GMT; path=/; domain=.wpseo.ml; HttpOnly; Secure
    Vary: Accept-Encoding
    Link: <https://wpseo.ml/wp-json/>; rel="https://api.w.org/"
    X-Powered-By: centminmod
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 419e7dabccc435fc-LHR
    Content-Encoding: gzip
    and for http command:
    Code:
    HTTP/1.1 301 Moved Permanently
    Date: Sat, 12 May 2018 17:10:14 GMT
    Connection: keep-alive
    Cache-Control: max-age=3600
    Expires: Sat, 12 May 2018 18:10:14 GMT
    Location: https://wpseo.ml/
    Server: cloudflare
    CF-RAY: 419e7f63c60535ae-LHR
    I have tried with runcloud.io. Same thing happening there too. After using cloudflare CDN brotli goes to gzip for wordpress blog without any caching plugin
     
  9. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    any wordpress caching methods used i.e. wp super cache or keycdn cache enabler ? check their settings to see if gzip compression is enabled.
     
  10. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    no. I have removed every cache plugin. Just using Disable XML-RPC and Optimus.

    I have tried with runcloud.io. Same thing happening there too. After using cloudflare CDN brotli goes to gzip for wordpress blog without any caching plugin
     
  11. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Only one file is served via brotli
    Code:
    https://fonts.googleapis.com/css?family=Libre+Franklin%3A300%2C300i%2C400%2C400i%2C600%2C600i%2C800%2C800i&subset=latin%2Clatin-ext
     
  12. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    Usually something either on nginx or web app (wordpress/forum software) is compressing static files as gzip first so it's served i.e. if you ran brotli.sh tool outlined at Sysadmin - How to use brotli.sh ? against your wordpress directory static files will be pre-compressed as gzip and brotli with gzip taking priority as nginx supports brotli and gzip pre compressed file serving.

    You can verify if cloudflare or centmin mod nginx is where the gzip compression is coming from by running curl command which bypasses cloudflare to connect with centmin mod nginx backend replacing YOURREALSERVER_IP with your real server IP address below and yourdomain.com with your domain name. You may want to mask your real ip when you post the output on this forum to protect your real IP address
    Code (Text):
    curl -sI -H"Accept-Encoding: gzip,br" --resolve 'yourdomain.com:443:YOURREALSERVER_IP' https://yourdomain.com
    

    compare it to header check with cloudflare in front
    Code (Text):
    curl -sI -H"Accept-Encoding: gzip,br" https://yourdomain.com
    

    Inspecting whether Content-Encoding shows br or gzip. If bypass curl header check shows br but cloudflare curl header check shows gzip, then something at web app level i.e. wordpress is precompressing static assets as gzip.
     
  13. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    HTTP/1.1 400 Bad Request
    Date: Sat, 12 May 2018 17:37:49 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 246
    Connection: close
    Server: nginx centminmod
    X-Powered-By: centminmod

    This is the output. Can not connect

    Update: Tried this command on runcloud server. It show Content-Encoding: br. So there must be something with cloudflare. Do you know anything to do with cloudflare for brotli other than brotli enable button.
     
    Last edited: May 13, 2018
  14. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Is there any specific setting you have to do in cloudflare for brotli compression apart from the enable brotli option, in speed tab in cloudflare?
     
  15. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Do i need to set "zlib.output_compression = Off" for brotli to work with wordpress.
    Found an article by sitepoint.com link below
    Code:
    https://www.sitepoint.com/brotli-compression-wordpress/
     
  16. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    If you have Cloudflare origin authentication setup so regular HTTPS requests to https backend nginx site are only allowed via Cloudflare, then need to temporarily disable Cloudflare origin authenitication by commenting out the line in your nginx vhost domain config file

    changing line from
    Code (Text):
    ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/domain.com/origin.crt;
    ssl_verify_client on;
    

    to comment out and disable them with hash in front
    Code (Text):
    #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/domain.com/origin.crt;
    #ssl_verify_client on;
    

    restart Nginx and PHP-FPM services
    Code (Text):
    nprestart
    

    Then disable Original Authentication Pull in Cloudflare dashboard.

    Then re-run single command line for curl header check that bypasses cloudflare
    Code (Text):
    curl -sI -H"Accept-Encoding: gzip,br" --resolve yourdomain.com:443:YOURREALSERVER_IP' https://yourdomain.com
    

    After you got output, re-enable Cloudflare origin authentication by removing comment hashes from the 2 lines and then restarting nginx and php-fpm services and re-enable Original Authentication Pull in Cloudflare dashboard.
     
    Last edited: May 13, 2018
  17. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    nope

    nope unless you manually set that to enabled as it should be left untouched
     
  18. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Yes. Its showing Content-Encoding: br. There's something with cloudflare :(
     
  19. eva2000

    eva2000 Administrator Staff Member

    34,242
    7,576
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +11,645
    Local Time:
    9:58 AM
    Nginx 1.13.x
    MariaDB 5.5
    Yes it's either Cloudflare or at web app level - something in wordpress is causing static assets to be compressed with gzip before being passed onto Cloudflare. You can try clearing Cloudflare cache - purge all cache button to see if that was caching your wordpress level gzipped assets.
     
  20. Nitin

    Nitin New Member

    23
    4
    3
    Apr 30, 2018
    Ratings:
    +4
    Local Time:
    5:28 AM
    Tried many time clearing cloudflare cache. Can i give you wordpress user and pass. See if you can do something. Its a fresh blog just to test different configuration nothing important in it.
     
..