Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tuning the NGINX - or how to make your website ...

Tuning the NGINX - or how to make your website faster

This is a talk first held at the Typo3 Developer Days 2019.
Watch the talk here: https://www.youtube.com/watch?v=czNKukCaA8M
Have a look at the configs here: https://github.com/foppelfb/nginx-talk

Frank Berger

August 02, 2019
Tweet

More Decks by Frank Berger

Other Decks in Programming

Transcript

  1. • Frank Berger (Greybeard) • Head of Engineering
 B-FACTOR Sudhaus7

    • started 1996 as Unix Systemadministrator who also programs (aka „Devops“) Sudhaus7 A SHORT NOTE ABOUT ME
  2. Sudhaus7 WHAT’S ON THE SERVER? • Debian Linux • PHP

    7.2 (opcache enabled) • MariaDB 10.4 (not tuned) 
 • Nginx 1.14 • Typo3 9.5.8
 • Shiny new Website, with lots of uncached USER_INT - because the Editor can’t wait to see the changes online
 (and we have lots of user input)
  3. Testing with siege 100 or more concurrent requests for 30

    seconds on a list of random urls LET’S TEST THE SERVER Sudhaus7
  4. worker_processes 3; worker_rlimit_nofile 40000; pcre_jit on; events { use epoll;

    worker_connections 1024; multiaccept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; } server { open_file_cache max=10000 inactive=30s; open_file_cache_valid 2m; open_file_cache_min_uses 2; open_file_cache_errors on; } WHAT CAN WE DO TO IMPROVE? Sudhaus7
  5. http { fastcgi_cache_path /var/run/nginx-fastcgi-cache levels=1:2 keys_zone=TYPO3:10m inactive=2m; fastcgi_cache_key "$scheme$request_method$host$uri$args"; fastcgi_cache_use_stale

    error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; } location ~ [^/]\.php(/|$) { set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($request_uri ~* "/typo3/|/index.php?eID=") { set $skip_cache 1; } if ($http_cookie ~* "be_typo_user|fe_typo_user") { set $skip_cache 1; } fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache TYPO3; fastcgi_cache_valid 200 10s; add_header X-FastCGI-Cache $upstream_cache_status; } Sudhaus7 NOT GOOD ENOUGH, WHAT ELSE?
  6. Sudhaus7 THE PROBLEM WITH THIS KIND OF CACHING • Everything

    gets cached for the specified time, even uncached content • Cache-Control Headers are ignored • There is no easy way to purge the cache 
 for a specific page
  7. config.sendCacheHeaders = 1 composer require ichhabrecht/intcache Replaces USER_INT with <!—#include

    virtual=„“—> to have a pageType call render the uncached content in a separate call Supports as well ESI (Varnish and Cloud flare) and AJAX Sudhaus7 EXTENSION FOR TYPO3
  8. http { fastcgi_ignore_headers Set-Cookie; } location ~ [^/]\.php(/|$) { ssi

    on; set $cachekey „$scheme$host$request_uri"; if ($args ~* "tx_intcache") { set $cachekey "$scheme$host$uri$args"; } fastcgi_cache_key $cachekey; } Sudhaus7 LET’S TRY
  9. Sudhaus7 ADVANTAGES/EFFECTS • Cache-Control Headers are recognised 
 and honoured

    by nginx
 • Uncached Content will be delivered directly, 
 but the surrounding page will stay cached • Extensions can send their own Cache-Control 
 headers based on their needs • Extensions can make better use of the Typo3 Cache 
 • Multiple uncached extensions in a 
 single Page can be handled separately
  10. • The NGINX Cache could be stored in a Redis

    cache
 enabling Failover Servers or Multiple Frontend Servers 
 using the same cached content • using the proxy_ variations of the configuration commands 
 can be used to set up a distributed cloud system • or using a docker-based backend, with the same 
 advantages as shown in this talk • The SSI technology can be used as well to include 
 Widgets from other frameworks or even technologies. Sudhaus7 OTHER COOL STUFF
  11. Frank Berger Sudhaus7 (eine Marke der B-FACTOR Gmbh) [email protected] Twitter:

    @foppelfb https://github.com/foppelfb Sudhaus7 THANK YOU!