$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Einführung in Nginx
Search
Dominik Siebel
September 27, 2012
Technology
0
250
Einführung in Nginx
Dominik Siebel
September 27, 2012
Tweet
Share
More Decks by Dominik Siebel
See All by Dominik Siebel
Einführung in Lucene Solr (PHPUG D/DU/KR)
dsiebel
0
110
Reguläre Ausdrucke (PCRE)
dsiebel
0
65
Other Decks in Technology
See All in Technology
RAG/Agent開発のアップデートまとめ
taka0709
0
130
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
21st ACRi Webinar - Univ of Tokyo Presentation Slide (Ayumi Ohno)
nao_sumikawa
0
120
プロダクトマネージャーが押さえておくべき、ソフトウェア資産とAIエージェント投資効果 / pmconf2025
i35_267
2
580
EM歴1年10ヶ月のぼくがぶち当たった苦悩とこれからへ向けて
maaaato
0
270
小さな判断で育つ、大きな意思決定力 / 20251204 Takahiro Kinjo
shift_evolve
PRO
1
570
AWS re:Invent 2025で見たGrafana最新機能の紹介
hamadakoji
0
110
非CUDAの悲哀 〜Claude Code と挑んだ image to 3D “Hunyuan3D”を EVO-X2(Ryzen AI Max+395)で動作させるチャレンジ〜
hawkymisc
1
160
ブロックテーマとこれからの WordPress サイト制作 / Toyama WordPress Meetup Vol.81
torounit
0
390
バグハンター視点によるサプライチェーンの脆弱性
scgajge12
3
970
ログ管理の新たな可能性?CloudWatchの新機能をご紹介
ikumi_ono
0
460
5分で知るMicrosoft Ignite
taiponrock
PRO
0
140
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Visualization
eitanlees
150
16k
It's Worth the Effort
3n
187
29k
Context Engineering - Making Every Token Count
addyosmani
9
490
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
92
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.8k
Transcript
Einführung in Nginx PHP Usergroup D / DU / KR
Dominik Siebel
From Russia with love
Wer von Euch setzt Nginx ein?
Nginx ➔ Entw. ~ 2002 Igor Sysoev ➔ C10k Problem
➔ Events statt Threads ➔ Version 1.2.0 ➔ BSD Lizenz
Nginx @ ... Wordpress.com GitHub Pinterest Golem Wikimedia Imageshack Soundcloud
... → Stand August 2012: 11,53% aller Webserver (1) Netcraft Studie
Web Server Reverse Proxy Mail Proxy Cache Load Balancer Und
mehr...
Woes & Awesomes
Pro ➔ Non-Blocking / Event basiert ➔ Mehr gleichzeitige Verbindungen
➔ Weniger Last ➔ Geringer Speicherverbrauch ➔ auch unter hoher Last
Pro ➔ Perl Interpreter (+ PCRE support) ➔ On-The-Fly Updates
➔ “Einfache” Konfiguration ➔ Aktive und hilfsbereite Community
Contra ➔ Keine .htacces ➔ Module nicht dynamisch ladbar ➔
Lückenhafte Dokumentation
Module
Module ➔ Core ➔ HTTP ➔ HTTP Erweiterungen http://wiki.nginx.org/Modules
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf ➔ Allgemeine Server Configuration ➔ Includes
user www-data pid /var/run/nginx.pid http { access_log /var/log/nginx/access_log error_log /var/log/nginx/error_log
}
http { gzip on; gzip_disable “msie6”; }
http { include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
/etc/nginx/sites-available/*
server ➔ “Virtual Host”
server { listen 80; server_name www.example.com root /var/www/example.com }
server { listen 80; server_name www.example.com root /var/www/example.com }
server { listen 80; server_name www.example.com server_name *.example.com server_name ~^www\d+\.example\.com
server_name - root /var/www/example.com }
location ➔ Am häufigsten verwendeter Block
location / { try_files $uri $uri/ /index.html; }
location /nginx/is/awesome { return 202; }
location ~ /\. { deny all; } Hide “dotfiles”
Kontexte
Kontexte Http ➔ Allgemeine Container/HTTP Modul Konfiguration Server ➔ “Virtual
Host” Location ➔ URL Handling Upstream ➔ Backend Konfiguration (z.B. Für Load Balancing)
Variablen
Variablen $scheme $host $request_method $request_uri
Variablen $arg_PARAM ➔ Direkter Zugriff auf URL Parameter
Variablen $http_HEADER ➔ Direkter Zugriff auf HTTP Request Header
Variablen $request_time ➔ Zeitspanne zwischen write() und read()
Variablen $upstream_response_time ➔ Antwortzeit des Backends
Variablen http://wiki.nginx.org/HttpCoreModule#Variables
Direktiven
Direktiven add_header add_header Cache-Control debug; ➔ Response Header
Direktiven proxy_set_header ➔ Header an Backend Server
Direktiven expires location ~ ^.+\.(jpg|jpeg|js|png) { expires 2h; } ➔
Browser Cache nach 2 Stunden invalidieren
Direktiven sub_filter ➔ Rechtschreibfehler Quickfix ;)
Direktiven error_pages error_page 400 /errors/404.html error_page 500 501 502 503
504 /errors/whoopsie.html ➔ Failwhales
Direktiven empty_gif location = /empty { empty_gif; }
Direktiven if set map rewrite ➔ Machtige Kontrollwerkzeuge
Direktiven http://wiki.nginx.org/HttpCoreModule#Directives
map
map $request_method $not_allowed_method { default 1; GET 0; HEAD 0;
POST 0; } if ($not_allowed_method) { return 405; }
rewrite
if ($args ~* format=json) { rewrite ^/$uri/?(.*)$ /$uri.json$1 break; }
if ($args ~* format=xml) { rewrite ^/$uri/?(.*)$ /$uri.xml$1 break; }
rewrite last → Stop und nochmal break → Weiter nach
rewrites redirect → 302 permanent → 301
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; }
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; }
rewrite - Domains server { server_name www.example.com return 301 $scheme://example.com$request_uri
}
Load Balancing
Round Robin
upstream web_workers { server www1.example.com; server www2.example.com; server www3.example.com; }
IP basiert
upstream web_workers { ip_hash; server www1.example.com; server www2.example.com; server www3.example.com;
}
Gewichtet
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; }
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
Nginx & PHP
upstream php { server unix:/var/run/php/www1.sock; }
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!
Benchmark ➔ Apache Benchmark (ab)
ab -n NREQ -c NCONC [-k] http://www.example.com/FILENAME
Benchmark ➔ Server & “Client” auf einem Server ➔ Request
logging deaktiviert ➔ Mit und ohne keepalive ➔ Durchschnitt aus 5 Testläufen
Benchmark ➔ HelloWorld.php – PHP, 13 bytes ➔ HelloWorld.txt –
statisch, 13 bytes ➔ 100KB.txt – statisch, 100 kb ➔ 1MB.txt – statisch, 1MB ➔ Index.php – “typischer” Frontcontroller
HelloWorld.php
HelloWorld.txt
100KB.txt
1MB.txt
Index.php
Apache PHP vs TXT
Nginx PHP vs TXT
Sollte ich zu Nginx wechseln? Überwiegend statischer Content → auf
jeden Fall Embedded / VPS → Ja Einfach so → vielleicht PHP Performanceoptimierung → Nein!
None
Danke! Fragen?
Quellen ➔ Wikipedia ➔ http://wiki.nginx.org ➔ https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi- and-nginx-dont-trust-the-tutorials-check-your-configuration/ ➔ https://speakerdeck.com/u/helgi/p/cranking-nginx-to-11-
dpc-2012 ➔ https://github.com/perusio/drupal-with-nginx ➔ http://blog.a2o.si/2009/06/24/apache-mod_php-compared- to-nginx-php-fpm/