Helgi Þormar Þorbjörnsson
DPC, Amsterdam, 2013
Nginx
The power within
Slide 2
Slide 2 text
Co-founded Orchestra.io
Work at EngineYard
PEAR Developer
From Iceland
@h on Twitter
Helgi
Slide 3
Slide 3 text
Nginx
Just a web server?
Slide 4
Slide 4 text
✓ Web Server
✓ Proxy
✓ Cache
✓ Mail Proxy
✓ And more!
No! It’s so much more!
Slide 5
Slide 5 text
Important for tweaking
Slide 6
Slide 6 text
Always run configtest before
doing anything!
Slide 7
Slide 7 text
Reload (HUP Signal)
Slide 8
Slide 8 text
Reload (HUP Signal)
‣ Reloads config
‣ Starts up new workers
‣ Old workers stop listening
‣ Finish up any work they have
Slide 9
Slide 9 text
Upgrade (USR2 Signal)
Slide 10
Slide 10 text
Upgrade (USR2 Signal)
‣ Live upgrade of Nginx executable
‣ Starts up a new Master
‣ Run in parallel
‣ Old Workers gracefully shutdown
‣ Old Master can be brought back
Slide 11
Slide 11 text
Requires --with-debug during build time
error_log /path/to/log debug;
Debugging
Responsible for all if statements, file exists
checks, returns and more.
Slide 18
Slide 18 text
Can work with most Nginx variables such
as $http_cookie,
$request_method,
$user_agent, $uri and countless
others.
Slide 19
Slide 19 text
j.mp/nginx_variables
List of variables
Slide 20
Slide 20 text
The power of SET
Text
set $helgi “Hi”;
Slide 21
Slide 21 text
Forward Domains
server {
server_name www.helgi.ws;
return 301 $scheme://helgi.ws$request_uri;
}
Slide 22
Slide 22 text
Load Balancing
Slide 23
Slide 23 text
upstream web_workers {
server www1.example.com;
server www2.example.com;
server www3.example.com;
server www4.example.com;
}
Simple Round Robin
Slide 24
Slide 24 text
Least Connection
upstream web_workers {
least_conn;
server www1.example.com;
server www2.example.com;
server www3.example.com;
server www4.example.com;
}
Slide 25
Slide 25 text
upstream web_workers {
ip_hash;
server www1.example.com;
server www2.example.com;
server www3.example.com;
server www4.example.com;
}
Consistent IP Routing
Slide 26
Slide 26 text
upstream web_workers {
server www1.example.com;
server www2.example.com
weight=2 max_fails=2 fail_timeout=15;
server www3.example.com
weight=4 max_fails=3;
server www4.example.com
weight=4 max_fails=4 fail_timeout=20;
keepalive 8;
}
Different Weights
weight and ip_hash can work
together in Nginx 1.3.1+