SlideShare a Scribd company logo
NGINX Installation and 
Tuning 
Introduced by Andrew Alexeev 
Presented by Owen Garrett 
Nginx, Inc.
About this webinar 
You’re ready to make your applications more responsive, scalable, fast and 
secure. Then it’s time to get started with NGINX. In this webinar, you will 
learn how to install NGINX from a package or from source onto a Linux 
host. We’ll then look at some common operating system tunings you could 
make to ensure your NGINX install is ready for prime time.
Agenda 
• Installing NGINX 
– Installation source, NGINX features 
• Tuning NGINX 
– Operating System tuning 
– NGINX software tuning 
• Benchmarking NGINX 
We’re covering a lot of material. 
Please feel free to take screenshots 
and read up afterwards.
BEFORE YOU INSTALL NGINX…
What can NGINX do for you? 
Internet 
N 
Web Server 
Serve content from disk 
Application Gateway 
FastCGI, uWSGI, Passenger… 
Proxy 
HTTP traffic Caching, Load Balancing… 
Application Acceleration 
SSL and SPDY termination 
Performance Monitoring 
High Availability 
Advanced Features: Bandwidth Management 
Content-based Routing 
Request Manipulation 
Response Rewriting 
Authentication 
Video Delivery 
Mail Proxy 
GeoLocation
Deployment Plan 
Determine the functionality you’ll need 
from NGINX: 
• Authentication 
• Proxy to API gateways 
• GZIP 
• GeoIP 
• etc. etc. 
Modules list at nginx.org
Three questions before installing NGINX 
1. What functionality do you require? 
• Standard modules 
• NGINX Plus functionality 
• Optional NGINX and third-party modules 
3. How do you want to install? 
• “Official” NGINX packages (nginx.org) 
• Build from Source 
• From Operating System repository 
• From Amazon AWS Marketplace 
2. What branch do you want to track? 
• Mainline (1.7) 
• Stable (1.6) 
• Something older? 
http://nginx.com/blog/ngi 
nx-1-6-1-7-released/
Recommended Install 
1. Standard modules (nginx.org) or NGINX Plus 
2. Mainline (1.7) 
3. Install from nginx.org or nginx-plus repository 
nginx.org builds do not include: 
• Modules with complex 3rd-party dependencies: 
• GeoIP, Image_Filter, Perl, XSLT 
• Modules that are part of NGINX Plus 
• Third-party modules e.g. Lua, Phusion Passenger 
http://nginx.com/products/technical-specs/
Difference between NGINX and NGINX Plus 
http://nginx.com/products/feature-matrix/ 
NGINX 
• High-performance, open 
source web server and 
accelerating proxy. 
• Community support through 
mailing lists on nginx.org, 
stackoverflow, subject 
experts etc. 
NGINX Plus 
• Adds Enterprise Load 
Balancing and Application 
Delivery features. 
• Full support and updates 
from NGINX Inc., the team 
who built and manage 
NGINX.
INSTALLING NGINX
Installation process 
$ wget http://nginx.org/keys/nginx_signing.key 
$ sudo apt-key add nginx_signing.key 
# cat > /etc/apt/sources.list.d/nginx.list 
deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx 
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx 
# apt-get update 
# apt-cache policy nginx 
nginx: 
Installed: (none) 
Candidate: 1.7.0-1~trusty 
Version table: 
1.7.0-1~trusty 0 
500 http://nginx.org/packages/mainline/ubuntu/ trusty/nginx amd64 Packages 
1.4.6-1ubuntu3 0 
500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages 
http://nginx.org/en/linux_packages.html#mainline
Verify that it is working 
# /etc/init.d/nginx status 
* nginx is running 
# /usr/sbin/nginx –v 
nginx version: nginx/1.7.0
TUNING NGINX 
#1: UNDERSTAND WHAT’S HAPPENING
Common tools 
• vmstat
Common tools 
• strace
Other tools 
• tcpdump / 
wireshark 
• Chrome 
dev tools 
• System log 
(dmesg –c)
TUNING NGINX: 
#2: TUNING THE OPERATING SYSTEM
Tuning the operating system 
• Basic tunables: 
– Backlog queue: limits number of 
pending connections 
– File descriptors: limit number of 
active connections 
– Ephemeral ports: limit number of 
upstream connections
Configuring Tunables - HOWTO 
• /proc: 
# echo "1" > /proc/sys/net/ipv4/tcp_syncookies 
• sysctl.conf: 
# vi /etc/sysctl.conf 
# Prevent against the common 'syn flood attack' 
net.ipv4.tcp_syncookies = 1 
# sysctl –p
The Backlog Queue 
• What happens when a connection is received? 
– SYN / SYNACK [syn_backlog queue] or syncookie 
– ACK [listen backlog queue] / NGINX:accept() 
– net.ipv4.tcp_max_syn_backlog 
– net.ipv4.tcp_syncookies 
– net.core.somaxconn 
• NGINX: listen backlog=1024 
– net.core.netdev_max_backlog
File Descriptors 
• What happens when a connection is processed? 
File descriptors are the key resource – estimate 2 per connection. 
– fs.file_max 
– /etc/security/limits.conf 
– worker_rlimit_nofile 200000;
Ephemeral Ports 
• What happens when NGINX proxies connections? 
Each TCP connection requires a unique 4-tuple: 
[src_ip:src_port, dst_ip:dst_port] 
Ephemeral port range and lifetime: 
– net.ipv4.ip_local_port_range 
– net.ipv4.tcp_fin_timeout
Keep checking kernel messages 
# dmesg -c 
# tail -f /var/log/kern.log
TUNING NGINX: 
#3: TUNING THE SOFTWARE
Tuning NGINX 
#1: You don’t need to “tune” very much 
#2: Don’t tune just for a benchmark 
#3: Use our Prof Services team to help
Common tunings 
worker_processes auto; – set to ‘auto’ or higher 
worker_connections – set to less than file descriptor 
count. 
accept_mutex: disable for busy services
The proxy should use keepalives 
Close TCP Connection 
(two-way handshake) 
Open TCP Connection 
(three-way handshake) 
Write HTTP request Read HTTP response 
Wait 
(timeout) 
NGINX or server 
closes the 
connection 
NGINX re-uses connection for another request 
server { 
listen 80; 
location / { 
proxy_pass http://backend; 
proxy_http_version 1.1; 
proxy_set_header Connection ""; 
} 
} 
upstream backend { 
server webserver1 max_conns=256; 
server webserver2 max_conns=256; 
queue 4096 timeout=15s; 
# maintain a maximum of 20 idle connections to each upstream server 
keepalive 20; 
}
BENCHMARKING NGINX
Why benchmark NGINX? 
1. To find how fast NGINX can go 
2. To tune NGINX for your workload 
3. To find where the bottlenecks are 
4. All of the above
IN CONCLUSION…
In conclusion: 
• Install from the nginx repo 
– NGINX or NGINX Plus 
• Basic tuning and configuration 
– dmesg / kern.log 
• Benchmark / stress test 
http://nginx.com/ 
• NGINX Professional Services and Training
NGINX Installation and Tuning
https://speakerdeck.com/dctrwatson/c1m-and-nginx 
https://www.youtube.com/watch?v=yL4Q7D4ynxU 
https://gist.github.com/dctrwatson/0b3b52050254e273ff11

More Related Content

What's hot (20)

PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
PDF
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
PPTX
High Availability Content Caching with NGINX
NGINX, Inc.
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
PPTX
Learn nginx in 90mins
Larry Cai
 
PPTX
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
PDF
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
PDF
[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region
Ji-Woong Choi
 
PPT
Nginx internals
liqiang xu
 
PPTX
5 things you didn't know nginx could do
sarahnovotny
 
PPTX
Nginx
Geeta Vinnakota
 
PDF
Nginx Essential
Gong Haibing
 
PDF
Deploy 22 microservices from scratch in 30 mins with GitOps
Opsta
 
PPTX
Introduction to Apache Camel
Claus Ibsen
 
PDF
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
PPTX
Room 3 - 7 - Nguyễn Như Phúc Huy - Vitastor: a fast and simple Ceph-like bloc...
Vietnam Open Infrastructure User Group
 
PDF
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
PDF
Ansible Introduction
Robert Reiz
 
PDF
IT Automation with Ansible
Rayed Alrashed
 
PPTX
NGINX: High Performance Load Balancing
NGINX, Inc.
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
High Availability Content Caching with NGINX
NGINX, Inc.
 
NGINX: High Performance Load Balancing
NGINX, Inc.
 
Learn nginx in 90mins
Larry Cai
 
Load Balancing and Scaling with NGINX
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region
Ji-Woong Choi
 
Nginx internals
liqiang xu
 
5 things you didn't know nginx could do
sarahnovotny
 
Nginx Essential
Gong Haibing
 
Deploy 22 microservices from scratch in 30 mins with GitOps
Opsta
 
Introduction to Apache Camel
Claus Ibsen
 
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
Room 3 - 7 - Nguyễn Như Phúc Huy - Vitastor: a fast and simple Ceph-like bloc...
Vietnam Open Infrastructure User Group
 
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
Ansible Introduction
Robert Reiz
 
IT Automation with Ansible
Rayed Alrashed
 
NGINX: High Performance Load Balancing
NGINX, Inc.
 

Viewers also liked (20)

PPTX
NGINX High-performance Caching
NGINX, Inc.
 
PDF
Nginx Internals
Joshua Zhu
 
PPTX
Maximizing PHP Performance with NGINX
NGINX, Inc.
 
PDF
Tuning TCP and NGINX on EC2
Chartbeat
 
PDF
How to secure your web applications with NGINX
Wallarm
 
PDF
How to monitor NGINX
Server Density
 
PPTX
Video Streaming. NGINX RTMP in particular
Anton Pinchuk
 
PDF
Naxsi, an open source WAF for Nginx
Positive Hack Days
 
PDF
Monitoring Highly Dynamic and Distributed Systems with NGINX Amplify
NGINX, Inc.
 
KEY
Nginx - Tips and Tricks.
Harish S
 
ODP
When dynamic becomes static : the next step in web caching techniques
Wim Godden
 
ODP
When dynamic becomes static : the next step in web caching techniques
Wim Godden
 
PPT
Streaming, Content Delivery & Networks Dr Angus Hay Neotel
guest22cb1ea7
 
PDF
Time-Series Monitoring Graphs with D3 & Rickshaw
Richard Powell
 
PDF
Nginx
Gordon Forsythe
 
PPTX
HTTP/2: Ask Me Anything
NGINX, Inc.
 
PPTX
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
PDF
Fisl15 Streaming de vídeo ao vivo na globo.com
Leandro Moreira
 
PPTX
What's New in HTTP/2
NGINX, Inc.
 
PPT
Tuning 17 march
Binan AL Halabi
 
NGINX High-performance Caching
NGINX, Inc.
 
Nginx Internals
Joshua Zhu
 
Maximizing PHP Performance with NGINX
NGINX, Inc.
 
Tuning TCP and NGINX on EC2
Chartbeat
 
How to secure your web applications with NGINX
Wallarm
 
How to monitor NGINX
Server Density
 
Video Streaming. NGINX RTMP in particular
Anton Pinchuk
 
Naxsi, an open source WAF for Nginx
Positive Hack Days
 
Monitoring Highly Dynamic and Distributed Systems with NGINX Amplify
NGINX, Inc.
 
Nginx - Tips and Tricks.
Harish S
 
When dynamic becomes static : the next step in web caching techniques
Wim Godden
 
When dynamic becomes static : the next step in web caching techniques
Wim Godden
 
Streaming, Content Delivery & Networks Dr Angus Hay Neotel
guest22cb1ea7
 
Time-Series Monitoring Graphs with D3 & Rickshaw
Richard Powell
 
HTTP/2: Ask Me Anything
NGINX, Inc.
 
WordPress + NGINX Best Practices with EasyEngine
NGINX, Inc.
 
Fisl15 Streaming de vídeo ao vivo na globo.com
Leandro Moreira
 
What's New in HTTP/2
NGINX, Inc.
 
Tuning 17 march
Binan AL Halabi
 
Ad

Similar to NGINX Installation and Tuning (20)

PDF
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
PPTX
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
PPTX
NGINX 101 - now with more Docker
sarahnovotny
 
PPTX
NGINX 101 - now with more Docker
Sarah Novotny
 
PPTX
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
PPTX
What's New in NGINX Plus R7?
NGINX, Inc.
 
PPTX
5 things you didn't know nginx could do velocity
sarahnovotny
 
PDF
tuning-nginx-for-high-performance-nick-shadrin.pdf
trihang02122018
 
PPTX
Installing and Configuring NGINX Open Source
NGINX, Inc.
 
PDF
How to Get Started With NGINX
NGINX, Inc.
 
PPTX
Basics of NGINX
Squash Apps Pvt Ltd
 
PPTX
NGINX Basics and Best Practices Workshop
NGINX, Inc.
 
PDF
NGINX: The Past, Present and Future of the Modern Web
Kevin Jones
 
PDF
ITB2017 - Nginx ppf intothebox_2017
Ortus Solutions, Corp
 
PPTX
Load Balancing Container with Nginx
Kumar Mayank
 
PDF
NginX - good practices, tips and advanced techniques
Claudio Borges
 
PDF
NGINX.conf 2016 - Fail in order to succeed ! Designing Microservices for fail...
Dragos Dascalita Haut
 
PDF
Lcu14 Lightning Talk- NGINX
Linaro
 
PPTX
Drupal 8 and NGINX
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
NGINX Basics: Ask Me Anything – EMEA
NGINX, Inc.
 
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX 101 - now with more Docker
Sarah Novotny
 
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
What's New in NGINX Plus R7?
NGINX, Inc.
 
5 things you didn't know nginx could do velocity
sarahnovotny
 
tuning-nginx-for-high-performance-nick-shadrin.pdf
trihang02122018
 
Installing and Configuring NGINX Open Source
NGINX, Inc.
 
How to Get Started With NGINX
NGINX, Inc.
 
Basics of NGINX
Squash Apps Pvt Ltd
 
NGINX Basics and Best Practices Workshop
NGINX, Inc.
 
NGINX: The Past, Present and Future of the Modern Web
Kevin Jones
 
ITB2017 - Nginx ppf intothebox_2017
Ortus Solutions, Corp
 
Load Balancing Container with Nginx
Kumar Mayank
 
NginX - good practices, tips and advanced techniques
Claudio Borges
 
NGINX.conf 2016 - Fail in order to succeed ! Designing Microservices for fail...
Dragos Dascalita Haut
 
Lcu14 Lightning Talk- NGINX
Linaro
 
Drupal 8 and NGINX
NGINX, Inc.
 
Ad

More from NGINX, Inc. (20)

PDF
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
NGINX, Inc.
 
PDF
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
NGINX, Inc.
 
PDF
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
NGINX, Inc.
 
PPTX
Get Hands-On with NGINX and QUIC+HTTP/3
NGINX, Inc.
 
PPTX
Managing Kubernetes Cost and Performance with NGINX & Kubecost
NGINX, Inc.
 
PDF
Manage Microservices Chaos and Complexity with Observability
NGINX, Inc.
 
PDF
Accelerate Microservices Deployments with Automation
NGINX, Inc.
 
PDF
Unit 2: Microservices Secrets Management 101
NGINX, Inc.
 
PDF
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
PDF
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX, Inc.
 
PDF
Easily View, Manage, and Scale Your App Security with F5 NGINX
NGINX, Inc.
 
PDF
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINX, Inc.
 
PDF
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
NGINX, Inc.
 
PPTX
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
NGINX, Inc.
 
PPTX
Protecting Apps from Hacks in Kubernetes with NGINX
NGINX, Inc.
 
PPTX
NGINX Kubernetes API
NGINX, Inc.
 
PPTX
Successfully Implement Your API Strategy with NGINX
NGINX, Inc.
 
PPTX
Shift Left for More Secure Apps with F5 NGINX
NGINX, Inc.
 
PPTX
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 
PDF
Kubernetes環境で実現するWebアプリケーションセキュリティ
NGINX, Inc.
 
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
NGINX, Inc.
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
NGINX, Inc.
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
NGINX, Inc.
 
Get Hands-On with NGINX and QUIC+HTTP/3
NGINX, Inc.
 
Managing Kubernetes Cost and Performance with NGINX & Kubecost
NGINX, Inc.
 
Manage Microservices Chaos and Complexity with Observability
NGINX, Inc.
 
Accelerate Microservices Deployments with Automation
NGINX, Inc.
 
Unit 2: Microservices Secrets Management 101
NGINX, Inc.
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX, Inc.
 
Easily View, Manage, and Scale Your App Security with F5 NGINX
NGINX, Inc.
 
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINX, Inc.
 
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
NGINX, Inc.
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
NGINX, Inc.
 
Protecting Apps from Hacks in Kubernetes with NGINX
NGINX, Inc.
 
NGINX Kubernetes API
NGINX, Inc.
 
Successfully Implement Your API Strategy with NGINX
NGINX, Inc.
 
Shift Left for More Secure Apps with F5 NGINX
NGINX, Inc.
 
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 
Kubernetes環境で実現するWebアプリケーションセキュリティ
NGINX, Inc.
 

Recently uploaded (20)

PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Simple and concise overview about Quantum computing..pptx
mughal641
 

NGINX Installation and Tuning

  • 1. NGINX Installation and Tuning Introduced by Andrew Alexeev Presented by Owen Garrett Nginx, Inc.
  • 2. About this webinar You’re ready to make your applications more responsive, scalable, fast and secure. Then it’s time to get started with NGINX. In this webinar, you will learn how to install NGINX from a package or from source onto a Linux host. We’ll then look at some common operating system tunings you could make to ensure your NGINX install is ready for prime time.
  • 3. Agenda • Installing NGINX – Installation source, NGINX features • Tuning NGINX – Operating System tuning – NGINX software tuning • Benchmarking NGINX We’re covering a lot of material. Please feel free to take screenshots and read up afterwards.
  • 5. What can NGINX do for you? Internet N Web Server Serve content from disk Application Gateway FastCGI, uWSGI, Passenger… Proxy HTTP traffic Caching, Load Balancing… Application Acceleration SSL and SPDY termination Performance Monitoring High Availability Advanced Features: Bandwidth Management Content-based Routing Request Manipulation Response Rewriting Authentication Video Delivery Mail Proxy GeoLocation
  • 6. Deployment Plan Determine the functionality you’ll need from NGINX: • Authentication • Proxy to API gateways • GZIP • GeoIP • etc. etc. Modules list at nginx.org
  • 7. Three questions before installing NGINX 1. What functionality do you require? • Standard modules • NGINX Plus functionality • Optional NGINX and third-party modules 3. How do you want to install? • “Official” NGINX packages (nginx.org) • Build from Source • From Operating System repository • From Amazon AWS Marketplace 2. What branch do you want to track? • Mainline (1.7) • Stable (1.6) • Something older? http://nginx.com/blog/ngi nx-1-6-1-7-released/
  • 8. Recommended Install 1. Standard modules (nginx.org) or NGINX Plus 2. Mainline (1.7) 3. Install from nginx.org or nginx-plus repository nginx.org builds do not include: • Modules with complex 3rd-party dependencies: • GeoIP, Image_Filter, Perl, XSLT • Modules that are part of NGINX Plus • Third-party modules e.g. Lua, Phusion Passenger http://nginx.com/products/technical-specs/
  • 9. Difference between NGINX and NGINX Plus http://nginx.com/products/feature-matrix/ NGINX • High-performance, open source web server and accelerating proxy. • Community support through mailing lists on nginx.org, stackoverflow, subject experts etc. NGINX Plus • Adds Enterprise Load Balancing and Application Delivery features. • Full support and updates from NGINX Inc., the team who built and manage NGINX.
  • 11. Installation process $ wget http://nginx.org/keys/nginx_signing.key $ sudo apt-key add nginx_signing.key # cat > /etc/apt/sources.list.d/nginx.list deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx # apt-get update # apt-cache policy nginx nginx: Installed: (none) Candidate: 1.7.0-1~trusty Version table: 1.7.0-1~trusty 0 500 http://nginx.org/packages/mainline/ubuntu/ trusty/nginx amd64 Packages 1.4.6-1ubuntu3 0 500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages http://nginx.org/en/linux_packages.html#mainline
  • 12. Verify that it is working # /etc/init.d/nginx status * nginx is running # /usr/sbin/nginx –v nginx version: nginx/1.7.0
  • 13. TUNING NGINX #1: UNDERSTAND WHAT’S HAPPENING
  • 16. Other tools • tcpdump / wireshark • Chrome dev tools • System log (dmesg –c)
  • 17. TUNING NGINX: #2: TUNING THE OPERATING SYSTEM
  • 18. Tuning the operating system • Basic tunables: – Backlog queue: limits number of pending connections – File descriptors: limit number of active connections – Ephemeral ports: limit number of upstream connections
  • 19. Configuring Tunables - HOWTO • /proc: # echo "1" > /proc/sys/net/ipv4/tcp_syncookies • sysctl.conf: # vi /etc/sysctl.conf # Prevent against the common 'syn flood attack' net.ipv4.tcp_syncookies = 1 # sysctl –p
  • 20. The Backlog Queue • What happens when a connection is received? – SYN / SYNACK [syn_backlog queue] or syncookie – ACK [listen backlog queue] / NGINX:accept() – net.ipv4.tcp_max_syn_backlog – net.ipv4.tcp_syncookies – net.core.somaxconn • NGINX: listen backlog=1024 – net.core.netdev_max_backlog
  • 21. File Descriptors • What happens when a connection is processed? File descriptors are the key resource – estimate 2 per connection. – fs.file_max – /etc/security/limits.conf – worker_rlimit_nofile 200000;
  • 22. Ephemeral Ports • What happens when NGINX proxies connections? Each TCP connection requires a unique 4-tuple: [src_ip:src_port, dst_ip:dst_port] Ephemeral port range and lifetime: – net.ipv4.ip_local_port_range – net.ipv4.tcp_fin_timeout
  • 23. Keep checking kernel messages # dmesg -c # tail -f /var/log/kern.log
  • 24. TUNING NGINX: #3: TUNING THE SOFTWARE
  • 25. Tuning NGINX #1: You don’t need to “tune” very much #2: Don’t tune just for a benchmark #3: Use our Prof Services team to help
  • 26. Common tunings worker_processes auto; – set to ‘auto’ or higher worker_connections – set to less than file descriptor count. accept_mutex: disable for busy services
  • 27. The proxy should use keepalives Close TCP Connection (two-way handshake) Open TCP Connection (three-way handshake) Write HTTP request Read HTTP response Wait (timeout) NGINX or server closes the connection NGINX re-uses connection for another request server { listen 80; location / { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Connection ""; } } upstream backend { server webserver1 max_conns=256; server webserver2 max_conns=256; queue 4096 timeout=15s; # maintain a maximum of 20 idle connections to each upstream server keepalive 20; }
  • 29. Why benchmark NGINX? 1. To find how fast NGINX can go 2. To tune NGINX for your workload 3. To find where the bottlenecks are 4. All of the above
  • 31. In conclusion: • Install from the nginx repo – NGINX or NGINX Plus • Basic tuning and configuration – dmesg / kern.log • Benchmark / stress test http://nginx.com/ • NGINX Professional Services and Training

Editor's Notes

  • #6: Does a lot of things… can sit at the center of your web infrastructure… worthwhile building a deployment plan
  • #7: Deployment plan will identify how many, where they are installed, what features are needed and will help to construct the configuration
  • #12: It’s a mess…. When I run apt-cache search nginx on Ubuntu14.04 with the nginx repo, I get 30 hits, 14 of which are nginx installation candidates. Only two of these are the ‘official’ nginx binaries
  • #27: accept_mutex; is on by default, should be off to reduce delay in accepts worker_processes; always auto. default 1. large amounts of diskio - set to larger than number of CPUs. e.g. consider wa column in vmstat, but be aware of other workloads on host keepalive_timeout; 75 seconds (check tcp keepalive) keepalive; (keepalive connection cache) how many sim conns can backend support? worker_connections - must be less than number of open files per process. will see message in error log if exceeded “worker_connections are not enough”. Should be a little less than number of fds per process
  • #28: Config in blue is nginx plus only
  • #30: Answer – to stress-test to determine where the problems are and address them with additional tuning where possible. You can’t rely on benchmark results to indicate real-world performance