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

Einführung in Nginx

Avatar for Dominik Siebel Dominik Siebel
September 27, 2012

Einführung in Nginx

Avatar for Dominik Siebel

Dominik Siebel

September 27, 2012
Tweet

More Decks by Dominik Siebel

Other Decks in Technology

Transcript

  1. Nginx ➔ Entw. ~ 2002 Igor Sysoev ➔ C10k Problem

    ➔ Events statt Threads ➔ Version 1.2.0 ➔ BSD Lizenz
  2. Nginx @ ... Wordpress.com GitHub Pinterest Golem Wikimedia Imageshack Soundcloud

    ... → Stand August 2012: 11,53% aller Webserver (1) Netcraft Studie
  3. Pro ➔ Non-Blocking / Event basiert ➔ Mehr gleichzeitige Verbindungen

    ➔ Weniger Last ➔ Geringer Speicherverbrauch ➔ auch unter hoher Last
  4. Pro ➔ Perl Interpreter (+ PCRE support) ➔ On-The-Fly Updates

    ➔ “Einfache” Konfiguration ➔ Aktive und hilfsbereite Community
  5. Kontexte Http ➔ Allgemeine Container/HTTP Modul Konfiguration Server ➔ “Virtual

    Host” Location ➔ URL Handling Upstream ➔ Backend Konfiguration (z.B. Für Load Balancing)
  6. map

  7. map $request_method $not_allowed_method { default 1; GET 0; HEAD 0;

    POST 0; } if ($not_allowed_method) { return 405; }
  8. if ($args ~* format=json) { rewrite ^/$uri/?(.*)$ /$uri.json$1 break; }

    if ($args ~* format=xml) { rewrite ^/$uri/?(.*)$ /$uri.xml$1 break; }
  9. rewrite last → Stop und nochmal break → Weiter nach

    rewrites redirect → 302 permanent → 301
  10. rewrite - Domains server { server_name www.example.com; rewrite ^/(.*)$ example.com/$1

    premanent; } server { server_name www.example.com; rewrite ^ example.com/$request_uri premanent; }
  11. rewrite - Domains server { server_name www.example.com; rewrite ^/(.*)$ example.com/$1

    premanent; } server { server_name www.example.com; rewrite ^ example.com/$request_uri premanent; }
  12. upstream web_workers { server www1.example.com weight=2 max_fails=2 fail_timeout=15; server www2.example.com

    weight=4 max_fails=3; server www3.example.com weight=4 max_fails=4 fail_timeout=20; }
  13. upstream web_workers { server www1.example.com weight=2 max_fails=2 fail_timeout=15; server www2.example.com

    weight=4 max_fails=3; server www3.example.com weight=4 max_fails=4 fail_timeout=20; } ip_hash + weight in Nginx >= 1.3.1
  14. location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include

    fastcgi_params; fastcgi_index index.php fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name fastcgi_param SERVER_NAME $host fastcgi_pass php; } Don't trust the tutorials!
  15. Benchmark ➔ Server & “Client” auf einem Server ➔ Request

    logging deaktiviert ➔ Mit und ohne keepalive ➔ Durchschnitt aus 5 Testläufen
  16. Benchmark ➔ HelloWorld.php – PHP, 13 bytes ➔ HelloWorld.txt –

    statisch, 13 bytes ➔ 100KB.txt – statisch, 100 kb ➔ 1MB.txt – statisch, 1MB ➔ Index.php – “typischer” Frontcontroller
  17. Sollte ich zu Nginx wechseln? Überwiegend statischer Content → auf

    jeden Fall Embedded / VPS → Ja Einfach so → vielleicht PHP Performanceoptimierung → Nein!