際際滷

際際滷Share a Scribd company logo
NGINX Installation and
Tuning
Introduced by Andrew Alexeev
Presented by Owen Garrett
Nginx, Inc.
About this webinar
Youre ready to make your applications more responsive, scalable, fast and
secure. Then its 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. Well 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
Were covering a lot of material.
Please feel free to take screenshots
and read up afterwards.
BEFORE YOU INSTALL 鰻赫鴛鰻掛
What can NGINX do for you?
Internet
N
Web Server
Serve content from disk
Application Gateway
FastCGI, uWSGI, Passenger
Proxy
Caching, Load Balancing
HTTP traffic
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 youll 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 WHATS 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 dont need to tune very much
#2: Dont 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
 NGINX Professional Services and Training
http://nginx.com/
proxy server for computer and web server .pdf
https://speakerdeck.com/dctrwatson/c1m-and-nginx
https://www.youtube.com/watch?v=yL4Q7D4ynxU
https://gist.github.com/dctrwatson/0b3b52050254e273ff11
Ad

Recommended

load balancing for web servers and .pdf
load balancing for web servers and .pdf
LakhanSingh873739
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report by Hubspot
2024 State of Marketing Report by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
SUN PATH AND SHADOW ANGLESarchitrcture.pdf
SUN PATH AND SHADOW ANGLESarchitrcture.pdf
14ANUSHAVPARCHI
Computer Network LAN MAN WAN layout model
Computer Network LAN MAN WAN layout model
electronicboi16
The_Geometry_of_Natshshshshshsbsure.pptx
The_Geometry_of_Natshshshshshsbsure.pptx
sambal5
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
Samuel Thuo
Exploratory Experiences Built by Design (UXPA25)
Exploratory Experiences Built by Design (UXPA25)
Design for Context
Numbers 1 to 100 Circle Flashcard s.pptx
Numbers 1 to 100 Circle Flashcard s.pptx
KarenGimena1
brain anatomy physiology 2025 short.pptx
brain anatomy physiology 2025 short.pptx
MohamedHany892810
Corneal_Edema_MCQs_with_answes click here
Corneal_Edema_MCQs_with_answes click here
priapria0901
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
ABHISHEKCHAKRABORTY931369
I2C EEPROM SIMULATION IN VERILOG-12.pptx
I2C EEPROM SIMULATION IN VERILOG-12.pptx
sudheerkurakula1218
PowerISO Crack 9.0 + Serial Key Free Download 2025
PowerISO Crack 9.0 + Serial Key Free Download 2025
Ayesha khan
Formal Informal Apology letter.pptxvvvvv
Formal Informal Apology letter.pptxvvvvv
iqlimajurayeva
Radiation_Pollution_eLearning_Module.pptx
Radiation_Pollution_eLearning_Module.pptx
kanishkaarora1496
Clamp_and_bend_device_exercisee_SFC.pptx
Clamp_and_bend_device_exercisee_SFC.pptx
DhanushJCS1
Quectel M10 AT commands Arduino Microcontroller
Quectel M10 AT commands Arduino Microcontroller
AdamSunusiHaruna1
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
Samuel Thuo
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
RandiAnugerah1
strees management for iuyagvdywyyqwdghuvuy.pptx
strees management for iuyagvdywyyqwdghuvuy.pptx
moonahish27
Exploring the Diverse Types of Textual Aids
Exploring the Diverse Types of Textual Aids
jenicahmendoza1
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
FaisalNurWibowo
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork

More Related Content

Recently uploaded (20)

SUN PATH AND SHADOW ANGLESarchitrcture.pdf
SUN PATH AND SHADOW ANGLESarchitrcture.pdf
14ANUSHAVPARCHI
Computer Network LAN MAN WAN layout model
Computer Network LAN MAN WAN layout model
electronicboi16
The_Geometry_of_Natshshshshshsbsure.pptx
The_Geometry_of_Natshshshshshsbsure.pptx
sambal5
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
Samuel Thuo
Exploratory Experiences Built by Design (UXPA25)
Exploratory Experiences Built by Design (UXPA25)
Design for Context
Numbers 1 to 100 Circle Flashcard s.pptx
Numbers 1 to 100 Circle Flashcard s.pptx
KarenGimena1
brain anatomy physiology 2025 short.pptx
brain anatomy physiology 2025 short.pptx
MohamedHany892810
Corneal_Edema_MCQs_with_answes click here
Corneal_Edema_MCQs_with_answes click here
priapria0901
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
ABHISHEKCHAKRABORTY931369
I2C EEPROM SIMULATION IN VERILOG-12.pptx
I2C EEPROM SIMULATION IN VERILOG-12.pptx
sudheerkurakula1218
PowerISO Crack 9.0 + Serial Key Free Download 2025
PowerISO Crack 9.0 + Serial Key Free Download 2025
Ayesha khan
Formal Informal Apology letter.pptxvvvvv
Formal Informal Apology letter.pptxvvvvv
iqlimajurayeva
Radiation_Pollution_eLearning_Module.pptx
Radiation_Pollution_eLearning_Module.pptx
kanishkaarora1496
Clamp_and_bend_device_exercisee_SFC.pptx
Clamp_and_bend_device_exercisee_SFC.pptx
DhanushJCS1
Quectel M10 AT commands Arduino Microcontroller
Quectel M10 AT commands Arduino Microcontroller
AdamSunusiHaruna1
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
Samuel Thuo
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
RandiAnugerah1
strees management for iuyagvdywyyqwdghuvuy.pptx
strees management for iuyagvdywyyqwdghuvuy.pptx
moonahish27
Exploring the Diverse Types of Textual Aids
Exploring the Diverse Types of Textual Aids
jenicahmendoza1
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
FaisalNurWibowo
SUN PATH AND SHADOW ANGLESarchitrcture.pdf
SUN PATH AND SHADOW ANGLESarchitrcture.pdf
14ANUSHAVPARCHI
Computer Network LAN MAN WAN layout model
Computer Network LAN MAN WAN layout model
electronicboi16
The_Geometry_of_Natshshshshshsbsure.pptx
The_Geometry_of_Natshshshshshsbsure.pptx
sambal5
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
FLOURISHING THROUGH SENSES: FROM AbSENSE to PreSENSE to EsSENSE to Re-...
Samuel Thuo
Exploratory Experiences Built by Design (UXPA25)
Exploratory Experiences Built by Design (UXPA25)
Design for Context
Numbers 1 to 100 Circle Flashcard s.pptx
Numbers 1 to 100 Circle Flashcard s.pptx
KarenGimena1
brain anatomy physiology 2025 short.pptx
brain anatomy physiology 2025 short.pptx
MohamedHany892810
Corneal_Edema_MCQs_with_answes click here
Corneal_Edema_MCQs_with_answes click here
priapria0901
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
AUTOMATIC NUMBER PLATE RECOGNITION 1.pptx
ABHISHEKCHAKRABORTY931369
I2C EEPROM SIMULATION IN VERILOG-12.pptx
I2C EEPROM SIMULATION IN VERILOG-12.pptx
sudheerkurakula1218
PowerISO Crack 9.0 + Serial Key Free Download 2025
PowerISO Crack 9.0 + Serial Key Free Download 2025
Ayesha khan
Formal Informal Apology letter.pptxvvvvv
Formal Informal Apology letter.pptxvvvvv
iqlimajurayeva
Radiation_Pollution_eLearning_Module.pptx
Radiation_Pollution_eLearning_Module.pptx
kanishkaarora1496
Clamp_and_bend_device_exercisee_SFC.pptx
Clamp_and_bend_device_exercisee_SFC.pptx
DhanushJCS1
Quectel M10 AT commands Arduino Microcontroller
Quectel M10 AT commands Arduino Microcontroller
AdamSunusiHaruna1
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
MULTI SENSORY EXPERIENCE DESIGN RESEARCH
Samuel Thuo
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
Figure.pptxfyytytyrrytrtytrttttrrttyyyyuuu
RandiAnugerah1
strees management for iuyagvdywyyqwdghuvuy.pptx
strees management for iuyagvdywyyqwdghuvuy.pptx
moonahish27
Exploring the Diverse Types of Textual Aids
Exploring the Diverse Types of Textual Aids
jenicahmendoza1
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
AVA-fundamentals-Gavin-Ambrose-Paul-Harris-The-fundamentals-of-typography-AVA...
FaisalNurWibowo

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
Ad

proxy server for computer and web server .pdf

  • 1. NGINX Installation and Tuning Introduced by Andrew Alexeev Presented by Owen Garrett Nginx, Inc.
  • 2. About this webinar Youre ready to make your applications more responsive, scalable, fast and secure. Then its 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. Well 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 Were covering a lot of material. Please feel free to take screenshots and read up afterwards.
  • 4. BEFORE YOU INSTALL 鰻赫鴛鰻掛
  • 5. What can NGINX do for you? Internet N Web Server Serve content from disk Application Gateway FastCGI, uWSGI, Passenger Proxy Caching, Load Balancing HTTP traffic 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 youll 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 WHATS 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 dont need to tune very much #2: Dont 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 NGINX Professional Services and Training http://nginx.com/