狠狠撸

狠狠撸Share a Scribd company logo
Load Balancing and
Scaling with NGINX
Introduced by Andrew Alexeev
Presented by Owen Garrett
Nginx, Inc.
About this webinar
When one server just isn’t enough, how can you scale out? In this
webinar, you'll learn how to build out the capacity of your website. You'll
see a variety of scalability approaches and some of the advanced
capabilities of NGINX Plus.
INTRODUCING NGINX…
What is NGINX?
Internet
N
Web Server
Serve content from disk
Application Server
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
143,000,000
Websites
NGINX Accelerates
22%
Top 1 million websites
37%
Top 1,000 websites
NGINX and NGINX Plus
NGINX F/OSS
nginx.org
3rd party
modules
Large community of >100 modules
NGINX and NGINX Plus
NGINX F/OSS
nginx.org
3rd party
modules
Large community of >100 modules
NGINX Plus
Advanced load balancing features
Ease-of-management
Commercial support
WHY LOAD-BALANCE?
Load-balancing Web Servers
Internet
N
? Improved Application Availability
? Management
? Increased Capacity
? Advanced techniques e.g. A|B testing
Why? ? DNS Round Robin
? Hardware L4 load balancer
? Software Reverse Proxy LB
? Cloud solution
How?
load balancing for web servers and   .pdf
Three Load Balancing case studies
Basic Load Balancing with NGINX
When you need more control
Advanced techniques
1
2
3
1. Basic Load Balancing
? Simple scalability
– All servers have same applications/services
– Load-balancer extracts optimal performance
Basic load balancing
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
upstream backend {
zone backend 64k;
server webserver1:80;
server webserver2:80;
server webserver3:80;
server webserver4:80;
}
Basic load balancing
? Use logging to debug: “$upstream_addr”
log_format combined2 '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$upstream_addr"';
192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80"
192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.2:80"
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80"
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.4:80"
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80"
192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.2:80"
192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80"
192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.4:80"
Basic Load Balancing
? Round-robin is the default
– Suitable for consistent pages
? Least Connections
– Suitable for varying pages
? IP Hash
– Fixed mapping, basic session
persistence
upstream backend {
server webserver1:80;
server webserver2:80;
}
upstream backend {
least_conn;
server webserver1:80;
server webserver2:80;
}
upstream backend {
ip_hash;
server webserver1:80;
server webserver2:80;
}
Managing the Upstream Group
? Direct config editing:
– nginx –s reload
– upstream.conf file:
? On-the-fly Reconfiguration [NGINX Plus only]
upstream backend {
server webserver1:80;
server webserver2:80;
server webserver3:80;
server webserver4:80;
}
$ curl 'http://localhost/upstream_conf?upstream=backend&id=3&down=1'
2. When you need more control…
? In many scenarios, you want more control over
where traffic is routed to:
– Primary and secondary servers (aka master/slave)
– Transaction state is accumulated on one server
Internet
‘Master’ and ‘Slave’ servers
? Wordpress admin traffic (e.g. image uploads)
N
‘Master’
‘Slave’
Copy image
uploads from
master to slave
‘Master’ and ‘Slave’ servers
? Wordpress admin traffic (e.g. image uploads)
N
server {
listen 80;
location ~ ^/(wp-admin|wp-login) {
proxy_pass http://wpadmin;
}
}
upstream wpadmin {
server server1:80;
server server2:80 backup;
}
‘Master’
‘Slave’
Session Persistence [NGINX Plus only]
? For when transaction state is accumulated on one server
– Shopping carts
– Advanced interactions
– Non-RESTful Applications
? NGINX Plus offers two methods:
– sticky cookie
– sticky route
“Session persistence also
helps performance”
Advanced Techniques
? You can control load-balancing programmatically
– A|B Testing
– Migration between applications
A|B Testing
Internet
N
‘backends’ upstream group
Test
server
95%
5%
Partition traffic.
Send 5% to new application instance
A|B Testing
split_clients "${remote_addr}AAA" $servers {
95% backends;
5% 192.168.56.1:80;
}
server {
listen 80;
location / {
proxy_pass http://$servers;
}
}
Application Migration
Internet
N
‘backendsA’ upstream group
‘backendsB’ upstream group
Create new generation of application
Migrate users from old to new
Preserve sessions, no interruptions
Application Migration
map $cookie_group $group {
~(?P<value>.+)$ $value;
default backendB; # The default upstream group
}
server {
listen 80;
location / {
add_header Set-Cookie "group=$group; path=/"
proxy_pass http://$group;
}
}
Three Load Balancing case studies
Basic Load Balancing with NGINX
When you need more control
Advanced techniques
1
2
3
Closing thoughts
? 37% of the busiest websites use NGINX
? Check out the load-balancing articles on
nginx.com/blog
? Future webinars: nginx.com/webinars
Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)

More Related Content

Recently uploaded (20)

PPTX
Communication skills - I.pptx hell o chadda i am here
u23ec178
?
DOCX
Are you scared to Buy Snapchat Accounts service online?
pvaway
?
DOCX
USCA Academy is a leading Canadian Private School for local and international...
sanaseo556
?
PPTX
FIRST REVIEW PPT-PENDEKANTI HARIKA(222T1F00B8)..pptx
ygomathibai
?
PPTX
办理方法澳洲硕士毕业证澳大利亚国家戏剧艺术学院文凭证书狈滨顿础学费单
Taqyea
?
PPTX
Blind stick project on robotics covering basics.pptx
ganamb
?
PDF
EC-770SE Coating Tester | Instromart Sensors
seoinstromart
?
PPTX
What were the national movements and the victory of the August Revolution .pptx
MinhKha41
?
PDF
Understanding First Loss Default Guarantee (FLDG)
Lokesh Agrawal
?
PPTX
Full_MDM_PC_Compromise_Report_Presentation_Final_WithVisuals.pptx
jasongriewing
?
PPTX
privacy preserving protocols in networking.pptx
jamesmay2663
?
PDF
[Back2School] STA Methodology- Chapter 7pdf
Ahmed Abdelazeem
?
PPT
cisco Network Associates Notes +++++++++
ssclengineer2025
?
PPT
426773238-ELECTRICAL-INSTALLATION-AND-MAINTENANCE-ppt (1).ppt
rhodalynpichon640
?
PPTX
Technology and LIvelihood education - ICTon
espinozajenneli
?
PDF
[Back2School] Crosstalk and Noise- Chapter 6.pdf
Ahmed Abdelazeem
?
PPTX
Q1W1D2 Exploring Tools and Equipment in ICT.pptx
TheodoraCatalan
?
PPTX
Q1W1D1 Exploring Tools and Equipment in ICT.pptx
TheodoraCatalan
?
PPTX
Q1W1D3 Types of Software in g7 ict subject.pptx
TheodoraCatalan
?
PPTX
Derivites constracts and its implications and uses
icuphamid
?
Communication skills - I.pptx hell o chadda i am here
u23ec178
?
Are you scared to Buy Snapchat Accounts service online?
pvaway
?
USCA Academy is a leading Canadian Private School for local and international...
sanaseo556
?
FIRST REVIEW PPT-PENDEKANTI HARIKA(222T1F00B8)..pptx
ygomathibai
?
办理方法澳洲硕士毕业证澳大利亚国家戏剧艺术学院文凭证书狈滨顿础学费单
Taqyea
?
Blind stick project on robotics covering basics.pptx
ganamb
?
EC-770SE Coating Tester | Instromart Sensors
seoinstromart
?
What were the national movements and the victory of the August Revolution .pptx
MinhKha41
?
Understanding First Loss Default Guarantee (FLDG)
Lokesh Agrawal
?
Full_MDM_PC_Compromise_Report_Presentation_Final_WithVisuals.pptx
jasongriewing
?
privacy preserving protocols in networking.pptx
jamesmay2663
?
[Back2School] STA Methodology- Chapter 7pdf
Ahmed Abdelazeem
?
cisco Network Associates Notes +++++++++
ssclengineer2025
?
426773238-ELECTRICAL-INSTALLATION-AND-MAINTENANCE-ppt (1).ppt
rhodalynpichon640
?
Technology and LIvelihood education - ICTon
espinozajenneli
?
[Back2School] Crosstalk and Noise- Chapter 6.pdf
Ahmed Abdelazeem
?
Q1W1D2 Exploring Tools and Equipment in ICT.pptx
TheodoraCatalan
?
Q1W1D1 Exploring Tools and Equipment in ICT.pptx
TheodoraCatalan
?
Q1W1D3 Types of Software in g7 ict subject.pptx
TheodoraCatalan
?
Derivites constracts and its implications and uses
icuphamid
?

Featured (20)

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

load balancing for web servers and .pdf

  • 1. Load Balancing and Scaling with NGINX Introduced by Andrew Alexeev Presented by Owen Garrett Nginx, Inc.
  • 2. About this webinar When one server just isn’t enough, how can you scale out? In this webinar, you'll learn how to build out the capacity of your website. You'll see a variety of scalability approaches and some of the advanced capabilities of NGINX Plus.
  • 4. What is NGINX? Internet N Web Server Serve content from disk Application Server 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. 22% Top 1 million websites 37% Top 1,000 websites
  • 7. NGINX and NGINX Plus NGINX F/OSS nginx.org 3rd party modules Large community of >100 modules
  • 8. NGINX and NGINX Plus NGINX F/OSS nginx.org 3rd party modules Large community of >100 modules NGINX Plus Advanced load balancing features Ease-of-management Commercial support
  • 10. Load-balancing Web Servers Internet N ? Improved Application Availability ? Management ? Increased Capacity ? Advanced techniques e.g. A|B testing Why? ? DNS Round Robin ? Hardware L4 load balancer ? Software Reverse Proxy LB ? Cloud solution How?
  • 12. Three Load Balancing case studies Basic Load Balancing with NGINX When you need more control Advanced techniques 1 2 3
  • 13. 1. Basic Load Balancing ? Simple scalability – All servers have same applications/services – Load-balancer extracts optimal performance
  • 14. Basic load balancing server { listen 80; location / { proxy_pass http://backend; } } upstream backend { zone backend 64k; server webserver1:80; server webserver2:80; server webserver3:80; server webserver4:80; }
  • 15. Basic load balancing ? Use logging to debug: “$upstream_addr” log_format combined2 '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$upstream_addr"'; 192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 192.168.56.1 - - [09/Mar/2014:23:08:56 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.2:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.4:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.1:80" 192.168.56.1 - - [09/Mar/2014:23:08:57 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.2:80" 192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET / HTTP/1.1" 200 30 "127.0.1.3:80" 192.168.56.1 - - [09/Mar/2014:23:08:58 +0000] "GET /favicon1.ico HTTP/1.1" 200 30 "127.0.1.4:80"
  • 16. Basic Load Balancing ? Round-robin is the default – Suitable for consistent pages ? Least Connections – Suitable for varying pages ? IP Hash – Fixed mapping, basic session persistence upstream backend { server webserver1:80; server webserver2:80; } upstream backend { least_conn; server webserver1:80; server webserver2:80; } upstream backend { ip_hash; server webserver1:80; server webserver2:80; }
  • 17. Managing the Upstream Group ? Direct config editing: – nginx –s reload – upstream.conf file: ? On-the-fly Reconfiguration [NGINX Plus only] upstream backend { server webserver1:80; server webserver2:80; server webserver3:80; server webserver4:80; } $ curl 'http://localhost/upstream_conf?upstream=backend&id=3&down=1'
  • 18. 2. When you need more control… ? In many scenarios, you want more control over where traffic is routed to: – Primary and secondary servers (aka master/slave) – Transaction state is accumulated on one server
  • 19. Internet ‘Master’ and ‘Slave’ servers ? Wordpress admin traffic (e.g. image uploads) N ‘Master’ ‘Slave’ Copy image uploads from master to slave
  • 20. ‘Master’ and ‘Slave’ servers ? Wordpress admin traffic (e.g. image uploads) N server { listen 80; location ~ ^/(wp-admin|wp-login) { proxy_pass http://wpadmin; } } upstream wpadmin { server server1:80; server server2:80 backup; } ‘Master’ ‘Slave’
  • 21. Session Persistence [NGINX Plus only] ? For when transaction state is accumulated on one server – Shopping carts – Advanced interactions – Non-RESTful Applications ? NGINX Plus offers two methods: – sticky cookie – sticky route “Session persistence also helps performance”
  • 22. Advanced Techniques ? You can control load-balancing programmatically – A|B Testing – Migration between applications
  • 23. A|B Testing Internet N ‘backends’ upstream group Test server 95% 5% Partition traffic. Send 5% to new application instance
  • 24. A|B Testing split_clients "${remote_addr}AAA" $servers { 95% backends; 5% 192.168.56.1:80; } server { listen 80; location / { proxy_pass http://$servers; } }
  • 25. Application Migration Internet N ‘backendsA’ upstream group ‘backendsB’ upstream group Create new generation of application Migrate users from old to new Preserve sessions, no interruptions
  • 26. Application Migration map $cookie_group $group { ~(?P<value>.+)$ $value; default backendB; # The default upstream group } server { listen 80; location / { add_header Set-Cookie "group=$group; path=/" proxy_pass http://$group; } }
  • 27. Three Load Balancing case studies Basic Load Balancing with NGINX When you need more control Advanced techniques 1 2 3
  • 28. Closing thoughts ? 37% of the busiest websites use NGINX ? Check out the load-balancing articles on nginx.com/blog ? Future webinars: nginx.com/webinars Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)