SlideShare a Scribd company logo
NGINX for FUN
& PERFORMANCEPHILIPP KRENN @xeraa ecosio
Vienna
ViennaDB
Papers We Love Vienna
Electronic Data Interchange (EDI)
nginx
there's this russian server nginx. all the
porn sites use it. it must be decent.
— Jonathan VanascoJV
JV
http://www.destructuring.net/2006/10/09/nginx/
From Subversion to Git
Users
WORDPRESS.COM APP
SERVER + LOAD BALANCER
UsersSTATIC CONTENT GITHUB
UsersSSL TERMINATION WIKIPEDIA
http://w3techs.com/technologies/cross/
web_server/ranking
http://news.netcraft.com/archives/2015/03/19/march-2015-web-
server-survey.html
http://news.netcraft.com/archives/2015/03/19/march-2015-web-
server-survey.html
Public launch in 2004 by
IGOR SYSOEV
HTTPS://WWW.RAMBLER.RU
BSD LICENSED
CROSS-PLATFORM C
STABLE 1.6.2 (2014-09-16)
PREVIEW 1.7.11 (2015-03-24)
SUPPORT FROM NGINX INC.
nginx is a lightweight event-driven
reverse proxy for web and mail services.
— http://nginx.org
Apache
THREAD / PROCESS-ORIENTED
SPAWN A PROCESS FOR EACH CONNECTION (1MB+ RAM)
APACHE 2.4 MULTI-PROCESS MODE REDUCES RAM USAGE
Problem200KB RESPONSE
MILLISECONDS TO GENERATE OR RETRIEVE
10S TO TRANSMIT AT 160KBPS (20KB/S)
1000 CONNECTIONS !
it's time for web servers to handle ten
thousand clients simultaneously
— Daniel Kegel
C10K challenge
NGINX SOLUTION
EVENT-DRIVEN ARCHITECTURE
Event-driven
SINGLE NONBLOCKING THREAD
ONE PROCESS PER CORE — NODE.JS, REDIS,...
STABLE MEMORY USAGE, NO CONTEXT SWITCHES
Event-driven1. Receive request
2. Trigger events in a process
3. Process handles events and returns output
http://en.wikipedia.org/wiki/Reactor_pattern
http://www.aosabook.org/en/nginx.html#fig.nginx.arch
!
EIERLEGENDE
WOLLMILCHSAU
"EGG-LAYING
WOOL-MILK-
SOW"
101Things nginx can do
000 SSL Termination
https://mozilla.github.io/server-side-tls/ssl-config-generator/
server {
listen 443 ssl;
ssl_certificate /path/to/signed_cert_plus_intermediates;
ssl_certificate_key /path/to/private_key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
# Better Perfect Forward Secrecy, generate: openssl dhparam 2048
ssl_dhparam /path/to/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:
ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:
DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:
kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:
ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:
ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:
ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:
DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:
DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:
DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:
AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:
CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:
!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
# HSTS: 15768000 seconds = 6 months
add_header Strict-Transport-Security max-age=15768000;
# OCSP Stapling
resolver 8.8.8.8 8.8.4.4;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
....
}
!
USE
https://mozilla.github.io/server-side-tls/ssl-config-generator/
https://www.ssllabs.com/ssltest/
001 Load Balancing
upstream backend_hosts {
server host0.example.com;
server host1.example.com;
server 10.10.10.10;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend_hosts;
}
}
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend_hosts;
}
UPSTREAM BALANCING ALGORITHM
DEFAULT: ROUND ROBIN
least_conn
ip_hash
hash
MOAR FEATURESCOOKIE STICKINESS
WEIGHTING OF NODES
...
010 Proxying
location / {
proxy_pass http://localhost:8000;
}
011 Dynamic Pages
location ~* .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_read_timeout 120;
}
100 A/B Testing
http {
split_clients "${remote_addr}" $designtest {
10% ".first";
10% ".second";
* "";
}
server {
listen 80;
server_name example.com;
index index${designtest}.html;
}
}
101 Client-Side Caching
location ~* ^.+.(htm|html|jpg|jpeg|gif|png|ico|css|
zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|
ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
access_log off;
expires max;
}
!
Apache is like Microsoft Word, it has a
million options but you only need six.
nginx does those six things, and it does
five of them 50 times faster than
Apache.
— Chris LeaCL
CL
http://maisonbisson.com/post/12249/chris-lea-on-nginx-and-wordpress/
GREAT! BUT...
...IT DOESN'T WORK THE
Apache WAY
FOR EXAMPLE .htaccess
FOR EVERY REQUEST, CHECK
EVERY DIRECTORY, READ AND
PARSE EVERY FILE
Changes effective immediately
http://example.com/assets/Uploads/gallery/image.jpg
Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015
DigitalOcean512MB RAM, 20GB SSD
UBUNTU 14.04 IN AMS2 + AMS3
ApacheBench
$ sudo apt-get install apache2-utils
$ ab -n 25000 -c 10 http://example.com
25,000 REQUESTS
CONCURRENCY 10, 50, 250, 1000
Vanilla installationsudo apt-get install apache2
sudo apt-get install nginx
NO TWEAKS
BEWARE
Unstable
$ ab -n 25000 -c 10 http://188.226.151.84/codemotion_intro.png
...
Server Software: nginx/1.4.6
Server Hostname: 188.226.151.84
Server Port: 80
Document Path: /codemotion_intro.png
Document Length: 2461 bytes
Concurrency Level: 10
Time taken for tests: 7.734 seconds
Complete requests: 25000
Failed requests: 0
Total transferred: 67575000 bytes
HTML transferred: 61525000 bytes
Requests per second: 3232.56 [#/sec] (mean)
Time per request: 3.094 [ms] (mean)
Time per request: 0.309 [ms] (mean, across all concurrent requests)
Transfer rate: 8532.82 [Kbytes/sec] received
...
Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015
Benchmarking 178.62.213.21 (be patient)
Completed 2500 requests
Completed 5000 requests
Completed 7500 requests
Completed 10000 requests
Completed 12500 requests
Completed 15000 requests
Completed 17500 requests
Completed 20000 requests
Completed 22500 requests
apr_socket_recv: Connection reset by peer (104)
Total of 24847 requests completed
$ ab -n 25000 -c 10
http://188.226.151.84/assets/Uploads/gallery/codemotion_intro.png
Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015
Add PHPsudo apt-get install php5-fpm
sudo apt-get install php5 libapache2-mod-php5
File<?php phpinfo();
ab -n 2500 -c 10 -l http://188.226.151.84/info.php
Concurrency Level: 10
Time taken for tests: 4.920 seconds
Complete requests: 2500
Failed requests: 0
Total transferred: 164667204 bytes
HTML transferred: 164252204 bytes
Requests per second: 508.18 [#/sec] (mean)
Time per request: 19.678 [ms] (mean)
Time per request: 1.968 [ms] (mean, across all concurrent requests)
Transfer rate: 32687.80 [Kbytes/sec] received
Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015
BENCHMARK YOUR PROJECTS
BUILD
BENCHMARK
REPEAT
Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015
Say Apache one
more time...
Questions?
NOW OR @XERAA
HTTPS://SPEAKERDECK.COM/XERAA/
Feedback
HTTPS://JOIND.IN/14161
HTTPS://JOIND.IN/EVENT/CODEMOTION-ROME-2015
IMAGE CREDIT
Rome https://flic.kr/p/j9Lmu
Vienna https://flic.kr/p/4enYGH
Database https://flic.kr/p/6QVfAK
Paper https://flic.kr/p/7Ahvn1
Engine https://flic.kr/p/hD3SY4
X https://flic.kr/p/9vMs2
Kiss https://flic.kr/p/z8Phh
Branches https://flic.kr/p/aDgLJx
Crowd https://flic.kr/p/Wd54U
Launch https://flic.kr/p/kjkJ5N
License https://flic.kr/p/nxAfZ
Release https://flic.kr/p/4rDBEK
Lightweight https://flic.kr/p/6h98Li
Apache https://flic.kr/p/8m9Mf1
Flow https://flic.kr/p/a5A3e1
Simultaneous https://flic.kr/p/easM1t
Speed https://flic.kr/p/afEu4o
Block https://flic.kr/p/8szrqe
Eierlegende Wollmilchsau https://flic.kr/p/GzQTT
Taipei https://flic.kr/p/4hi1jB
Terminator https://flic.kr/p/6hDYBK
Load https://flic.kr/p/mhuXC5
Balance https://flic.kr/p/bpeZXt
Huge https://flic.kr/p/p8tTGE
Between https://flic.kr/p/cXHXH3
Dynamic https://flic.kr/p/qzpdr9
Two https://flic.kr/p/9Jpzfz
Fixed https://flic.kr/p/21CsBV
Word https://flic.kr/p/913FL2
Different https://flic.kr/p/aUwPzp
Access https://flic.kr/p/KA324
Sad https://flic.kr/p/9g5Gg8
Ocean https://flic.kr/p/fQ3pxX
Bench https://flic.kr/p/kbpHr3
Vanilla https://flic.kr/p/b4iChr
PHP https://flic.kr/p/4o1dFf
Test https://flic.kr/p/adiTK3

More Related Content

PDF
Puppet Camp London Fall 2015 - Service Discovery and Puppet
PPTX
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PDF
Automating the Network
PDF
The Good Parts / The Hard Parts
PDF
Salt conf 2014 - Using SaltStack in high availability environments
PDF
Aeon mike guide transparent ssl filtering (1)
PDF
Aeon mike guide transparent ssl filtering
PDF
Puppet in the Pipeline
Puppet Camp London Fall 2015 - Service Discovery and Puppet
PHP on Heroku: Deploying and Scaling Apps in the Cloud
Automating the Network
The Good Parts / The Hard Parts
Salt conf 2014 - Using SaltStack in high availability environments
Aeon mike guide transparent ssl filtering (1)
Aeon mike guide transparent ssl filtering
Puppet in the Pipeline

What's hot (20)

PPTX
So I Wrote a Manifest
PDF
[MeetUp][2nd] 컭on턺
PDF
Release with confidence
PPTX
SaltConf 2015: Salt stack at web scale: Better, Stronger, Faster
PDF
Taming AEM deployments
KEY
Push the web with HTML5
PDF
Salt conf 2014-installing-openstack-using-saltstack-v02
PDF
Badge Poser v3.0 - A DevOps Journey
PDF
How to contribute Apache CloudStack
PDF
mykola marzhan - jenkins on aws spot instance
PDF
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
PDF
Service discovery and puppet
PDF
HTTP colon slash slash: the end of the road?
PDF
SDPHP - Percona Toolkit (It's Basically Magic)
PDF
Deploying Plone on AWS
PPTX
Vagrant introduction for Developers
PDF
Multiple django applications on a single server with nginx
ODP
Setting up and open fidy dev environment
PPTX
SQL Server On SANs
PPT
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
So I Wrote a Manifest
[MeetUp][2nd] 컭on턺
Release with confidence
SaltConf 2015: Salt stack at web scale: Better, Stronger, Faster
Taming AEM deployments
Push the web with HTML5
Salt conf 2014-installing-openstack-using-saltstack-v02
Badge Poser v3.0 - A DevOps Journey
How to contribute Apache CloudStack
mykola marzhan - jenkins on aws spot instance
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
Service discovery and puppet
HTTP colon slash slash: the end of the road?
SDPHP - Percona Toolkit (It's Basically Magic)
Deploying Plone on AWS
Vagrant introduction for Developers
Multiple django applications on a single server with nginx
Setting up and open fidy dev environment
SQL Server On SANs
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
Ad

Similar to Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015 (20)

PDF
What is Nginx and Why You Should to Use it with Wordpress Hosting
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
PPTX
NGINX: Basics and Best Practices
PDF
Web servers presentacion
PDF
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PDF
Deploying nginx with minimal system resources
PPTX
5 things you didn't know nginx could do velocity
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
PDF
NGINX ADC: Basics and Best Practices – EMEA
PPTX
Web Servers(IIS, NGINX, APACHE)
DOC
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
ODP
Introduction to Nginx
PDF
NGINX: Basics and Best Practices EMEA
PDF
NGINX: The Past, Present and Future of the Modern Web
PDF
ITB2017 - Nginx ppf intothebox_2017
PPTX
5 things you didn't know nginx could do
PPTX
NGINX 101 - now with more Docker
PPTX
NGINX 101 - now with more Docker
PPTX
Basics of NGINX
What is Nginx and Why You Should to Use it with Wordpress Hosting
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
NGINX: Basics and Best Practices
Web servers presentacion
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
Deploying nginx with minimal system resources
5 things you didn't know nginx could do velocity
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
NGINX ADC: Basics and Best Practices – EMEA
Web Servers(IIS, NGINX, APACHE)
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
Introduction to Nginx
NGINX: Basics and Best Practices EMEA
NGINX: The Past, Present and Future of the Modern Web
ITB2017 - Nginx ppf intothebox_2017
5 things you didn't know nginx could do
NGINX 101 - now with more Docker
NGINX 101 - now with more Docker
Basics of NGINX
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PPTX
ai tools demonstartion for schools and inter college
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Digital Strategies for Manufacturing Companies
PDF
AI in Product Development-omnex systems
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
top salesforce developer skills in 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
ai tools demonstartion for schools and inter college
Design an Analysis of Algorithms II-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Reimagine Home Health with the Power of Agentic AI​
Design an Analysis of Algorithms I-SECS-1021-03
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Digital Strategies for Manufacturing Companies
AI in Product Development-omnex systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
Understanding Forklifts - TECH EHS Solution
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
top salesforce developer skills in 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Upgrade and Innovation Strategies for SAP ERP Customers
Operating system designcfffgfgggggggvggggggggg
Wondershare Filmora 15 Crack With Activation Key [2025

Nginx for Fun & Performance - Philipp Krenn - Codemotion Rome 2015