SlideShare a Scribd company logo
1 of 18
Download to read offline
NginxNginx
your load balancer & cacheyour load balancer & cache
MarianMarian HackManHackMan Marinov <mm@1h.com>Marinov <mm@1h.com>
CEO of 1H Ltd.CEO of 1H Ltd.
Why load balance with Nginx?Why load balance with Nginx?
Why load balance with Nginx?Why load balance with Nginx?
Why not do it with other tools?Why not do it with other tools?
➢ Balancing with iptablesBalancing with iptables
➢ Balancing with iproute2Balancing with iproute2
➢ LinuxVserverLinuxVserver
➢ HAproxyHAproxy
➢ VarnishVarnish
➢ even Apache can do iteven Apache can do it
with mod_proxy_balancerwith mod_proxy_balancer
sample.comsample.com
IN A 10.0.0.1IN A 10.0.0.1
IN A 10.0.0.2IN A 10.0.0.2
10.0.0.110.0.0.1 10.0.0.210.0.0.2
DNS balancingDNS balancing
sample.comsample.com
IN A 10.0.0.1IN A 10.0.0.1
IN A 10.0.0.2IN A 10.0.0.2
10.0.0.110.0.0.1 10.0.0.210.0.0.2
10.0.0.110.0.0.1
Fault ToleranceFault Tolerance
High AvailabilityHigh Availability
➢Always have at least two LB nodesAlways have at least two LB nodes
➢Use DNS balancingUse DNS balancing
(two A/AAAA) records(two A/AAAA) records
➢Use vrrpd or keepalivedUse vrrpd or keepalived
for floating IPs (on layer 2)for floating IPs (on layer 2)
➢In more complex network setupsIn more complex network setups
Corosync + PacemakerCorosync + Pacemaker
Make sure your infrastructureMake sure your infrastructure
can handle a single LB failurecan handle a single LB failure
(has enough resources CPU, Bandwidth)(has enough resources CPU, Bandwidth)
Load balancing with NginxLoad balancing with Nginx
Load balancing with NginxLoad balancing with Nginx
➢ upstreamupstream
➢ scgi/uwsgi/fastcgi/memcachedscgi/uwsgi/fastcgi/memcached
➢_pass (using upstream)_pass (using upstream)
➢_next_server_next_server
➢ upstream_conf (commercial)upstream_conf (commercial)
➢ Your own monitoringYour own monitoring
Load balancing with NginxLoad balancing with Nginx
synopsis:synopsis:
server IP [options];server IP [options];
upstream static_backend {upstream static_backend {
server 10.0.0.1 fail_timeout=5s max_fails=1;server 10.0.0.1 fail_timeout=5s max_fails=1;
server 10.0.0.2 fail_timeout=5s max_fails=1;server 10.0.0.2 fail_timeout=5s max_fails=1;
keepalive 512;keepalive 512;
}}
Load balancing with NginxLoad balancing with Nginx
weight=numberweight=number
max_fails=numbermax_fails=number
fail_timeout=timefail_timeout=time
backupbackup
downdown
max_conns=numbermax_conns=number
resolveresolve
slow_start=timeslow_start=time
Load balancing with NginxLoad balancing with Nginx
Request distribution methodRequest distribution method
➢ round-robin (default)round-robin (default)
➢ ip_haship_hash
➢ hashhash
➢ least_connleast_conn
➢ least_timeleast_time header/bytesheader/bytes
Load balancing with NginxLoad balancing with Nginx
keepalivekeepalive
health_check [parameters]health_check [parameters]
match namematch name
queue number [timeout=time]queue number [timeout=time]
sticky cookie namesticky cookie name
Load balancing with NginxLoad balancing with Nginx
health_check interval=1 uri=/health;health_check interval=1 uri=/health;
# status ok and not in maintenance mode# status ok and not in maintenance mode
match server_ok {match server_ok {
status 200-399;status 200-399;
body !~ "maintenance mode";body !~ "maintenance mode";
}}
Caching in NginxCaching in Nginx
➢ Why not cache the static content?Why not cache the static content?
➢ Limited ESI support troughLimited ESI support trough
ngx_http_ssi and ngx_esingx_http_ssi and ngx_esi
➢ Handle traffic extremesHandle traffic extremes
withwith stale cachingstale caching
➢ Reduce response timesReduce response times
If there are people willing to extend ngx_esiIf there are people willing to extend ngx_esi
I would join forces with them!I would join forces with them!
Caching in NginxCaching in Nginx
proxy_cache_path /var/lib/nginx/cacheproxy_cache_path /var/lib/nginx/cache
levels=1:2 keys_zone=WP:1024mlevels=1:2 keys_zone=WP:1024m
max_size=2048m;max_size=2048m;
proxy_cache_keyproxy_cache_key
"$host$request_uri $cookie_user";"$host$request_uri $cookie_user";
proxy_cache_valid 200 301 302 2s;proxy_cache_valid 200 301 302 2s;
proxy_cache_use_staleproxy_cache_use_stale
error timeout invalid_header updating;error timeout invalid_header updating;
expires 60s;expires 60s;
?/? Questions ?/??/? Questions ?/?
MarianMarian HackManHackMan MarinovMarinov
<mm@1h.com><mm@1h.com>
CEO of 1H Ltd.CEO of 1H Ltd.
Thank Youuuuuu!!!Thank Youuuuuu!!!

More Related Content

What's hot

High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheKevin Jones
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?Albert Chen
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react nativeDani Akash
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX, Inc.
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleKnoldus Inc.
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX, Inc.
 
How to Get Started With NGINX
How to Get Started With NGINXHow to Get Started With NGINX
How to Get Started With NGINXNGINX, Inc.
 
Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Chartbeat
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 
NGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX, Inc.
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django ArchitectureRami Sayar
 

What's hot (20)

Ansible
AnsibleAnsible
Ansible
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Using NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content CacheUsing NGINX as an Effective and Highly Available Content Cache
Using NGINX as an Effective and Highly Available Content Cache
 
How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?How to Build a High Performance Application with PHP and Swoole?
How to Build a High Performance Application with PHP and Swoole?
 
Nginx
NginxNginx
Nginx
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Swoole w PHP. Czy to ma sens?
Swoole w PHP. Czy to ma sens?Swoole w PHP. Czy to ma sens?
Swoole w PHP. Czy to ma sens?
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
How to Get Started With NGINX
How to Get Started With NGINXHow to Get Started With NGINX
How to Get Started With NGINX
 
Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Rust
RustRust
Rust
 
NGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEA
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 

Viewers also liked

NGiNX, o motor da sua aplicação web
NGiNX, o motor da sua aplicação webNGiNX, o motor da sua aplicação web
NGiNX, o motor da sua aplicação webernaniaz
 
Liliana rivas gonzalez_actividad1_mapa_c
Liliana rivas gonzalez_actividad1_mapa_cLiliana rivas gonzalez_actividad1_mapa_c
Liliana rivas gonzalez_actividad1_mapa_clilianarigo
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90minsLarry Cai
 
What's New in NGINX Plus R10?
What's New in NGINX Plus R10?What's New in NGINX Plus R10?
What's New in NGINX Plus R10?NGINX, Inc.
 
The 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureThe 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureNGINX, Inc.
 
Load Balancing Apps in Docker Swarm with NGINX
Load Balancing Apps in Docker Swarm with NGINXLoad Balancing Apps in Docker Swarm with NGINX
Load Balancing Apps in Docker Swarm with NGINXNGINX, Inc.
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Trygve Vea
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx InternalsJoshua Zhu
 

Viewers also liked (8)

NGiNX, o motor da sua aplicação web
NGiNX, o motor da sua aplicação webNGiNX, o motor da sua aplicação web
NGiNX, o motor da sua aplicação web
 
Liliana rivas gonzalez_actividad1_mapa_c
Liliana rivas gonzalez_actividad1_mapa_cLiliana rivas gonzalez_actividad1_mapa_c
Liliana rivas gonzalez_actividad1_mapa_c
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
What's New in NGINX Plus R10?
What's New in NGINX Plus R10?What's New in NGINX Plus R10?
What's New in NGINX Plus R10?
 
The 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference ArchitectureThe 3 Models in the NGINX Microservices Reference Architecture
The 3 Models in the NGINX Microservices Reference Architecture
 
Load Balancing Apps in Docker Swarm with NGINX
Load Balancing Apps in Docker Swarm with NGINXLoad Balancing Apps in Docker Swarm with NGINX
Load Balancing Apps in Docker Swarm with NGINX
 
Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!Extending functionality in nginx, with modules!
Extending functionality in nginx, with modules!
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 

Similar to Load Balancing with Nginx

NSClient Workshop: 04 Protocols
NSClient Workshop: 04 ProtocolsNSClient Workshop: 04 Protocols
NSClient Workshop: 04 ProtocolsMichael Medin
 
20110701 zsc2011-advanced proxying-formatted
20110701 zsc2011-advanced proxying-formatted20110701 zsc2011-advanced proxying-formatted
20110701 zsc2011-advanced proxying-formattedZarafa
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7VCP Muthukrishna
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_phpRenato Lucena
 
ByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedredhat9
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open sourceIngo Walz
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesSeveralnines
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesSeveralnines
 
Django and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheDjango and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheAnton Pirker
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for DevelopersAntons Kranga
 
Migrating to a Bazel-based CI System: 6 Learnings - Or Shachar
Migrating to a Bazel-based CI System: 6 Learnings - Or ShacharMigrating to a Bazel-based CI System: 6 Learnings - Or Shachar
Migrating to a Bazel-based CI System: 6 Learnings - Or ShacharWix Engineering
 
Free enterpriseloadbalancer
Free enterpriseloadbalancerFree enterpriseloadbalancer
Free enterpriseloadbalancermikesoule
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginXbilldigman
 

Similar to Load Balancing with Nginx (20)

Wckansai 2014
Wckansai 2014Wckansai 2014
Wckansai 2014
 
NSClient Workshop: 04 Protocols
NSClient Workshop: 04 ProtocolsNSClient Workshop: 04 Protocols
NSClient Workshop: 04 Protocols
 
20110701 zsc2011-advanced proxying-formatted
20110701 zsc2011-advanced proxying-formatted20110701 zsc2011-advanced proxying-formatted
20110701 zsc2011-advanced proxying-formatted
 
How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7How To Configure Nginx Load Balancer on CentOS 7
How To Configure Nginx Load Balancer on CentOS 7
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_php
 
ByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalived
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open source
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - Slides
 
Dev ops for developers
Dev ops for developersDev ops for developers
Dev ops for developers
 
Django and Nginx reverse proxy cache
Django and Nginx reverse proxy cacheDjango and Nginx reverse proxy cache
Django and Nginx reverse proxy cache
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
DevOps for Developers
DevOps for DevelopersDevOps for Developers
DevOps for Developers
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Migrating to a Bazel-based CI System: 6 Learnings - Or Shachar
Migrating to a Bazel-based CI System: 6 Learnings - Or ShacharMigrating to a Bazel-based CI System: 6 Learnings - Or Shachar
Migrating to a Bazel-based CI System: 6 Learnings - Or Shachar
 
Free enterpriseloadbalancer
Free enterpriseloadbalancerFree enterpriseloadbalancer
Free enterpriseloadbalancer
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Nginx
NginxNginx
Nginx
 
PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginX
 

More from Marian Marinov

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingMarian Marinov
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsMarian Marinov
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Marian Marinov
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDBMarian Marinov
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMarian Marinov
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfMarian Marinov
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home eraMarian Marinov
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefsMarian Marinov
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd Marian Marinov
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storageMarian Marinov
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Marian Marinov
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL serverMarian Marinov
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKMarian Marinov
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networksMarian Marinov
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automationMarian Marinov
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingMarian Marinov
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of serversMarian Marinov
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failuresMarian Marinov
 

More from Marian Marinov (20)

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanisms
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDB
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdf
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home era
 
Managing sysadmins
Managing sysadminsManaging sysadmins
Managing sysadmins
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefs
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL server
 
Sysadmin vs. dev ops
Sysadmin vs. dev opsSysadmin vs. dev ops
Sysadmin vs. dev ops
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networks
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automation
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel tracking
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of servers
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failures
 

Recently uploaded

Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesLumiverse Solutions Pvt Ltd
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 

Recently uploaded (9)

Cybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best PracticesCybersecurity Threats and Cybersecurity Best Practices
Cybersecurity Threats and Cybersecurity Best Practices
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 

Load Balancing with Nginx

  • 1. NginxNginx your load balancer & cacheyour load balancer & cache MarianMarian HackManHackMan Marinov <mm@1h.com>Marinov <mm@1h.com> CEO of 1H Ltd.CEO of 1H Ltd.
  • 2. Why load balance with Nginx?Why load balance with Nginx?
  • 3. Why load balance with Nginx?Why load balance with Nginx? Why not do it with other tools?Why not do it with other tools?
  • 4. ➢ Balancing with iptablesBalancing with iptables ➢ Balancing with iproute2Balancing with iproute2 ➢ LinuxVserverLinuxVserver ➢ HAproxyHAproxy ➢ VarnishVarnish ➢ even Apache can do iteven Apache can do it with mod_proxy_balancerwith mod_proxy_balancer
  • 5. sample.comsample.com IN A 10.0.0.1IN A 10.0.0.1 IN A 10.0.0.2IN A 10.0.0.2 10.0.0.110.0.0.1 10.0.0.210.0.0.2 DNS balancingDNS balancing
  • 6. sample.comsample.com IN A 10.0.0.1IN A 10.0.0.1 IN A 10.0.0.2IN A 10.0.0.2 10.0.0.110.0.0.1 10.0.0.210.0.0.2 10.0.0.110.0.0.1 Fault ToleranceFault Tolerance High AvailabilityHigh Availability
  • 7. ➢Always have at least two LB nodesAlways have at least two LB nodes ➢Use DNS balancingUse DNS balancing (two A/AAAA) records(two A/AAAA) records ➢Use vrrpd or keepalivedUse vrrpd or keepalived for floating IPs (on layer 2)for floating IPs (on layer 2) ➢In more complex network setupsIn more complex network setups Corosync + PacemakerCorosync + Pacemaker Make sure your infrastructureMake sure your infrastructure can handle a single LB failurecan handle a single LB failure (has enough resources CPU, Bandwidth)(has enough resources CPU, Bandwidth)
  • 8. Load balancing with NginxLoad balancing with Nginx
  • 9. Load balancing with NginxLoad balancing with Nginx ➢ upstreamupstream ➢ scgi/uwsgi/fastcgi/memcachedscgi/uwsgi/fastcgi/memcached ➢_pass (using upstream)_pass (using upstream) ➢_next_server_next_server ➢ upstream_conf (commercial)upstream_conf (commercial) ➢ Your own monitoringYour own monitoring
  • 10. Load balancing with NginxLoad balancing with Nginx synopsis:synopsis: server IP [options];server IP [options]; upstream static_backend {upstream static_backend { server 10.0.0.1 fail_timeout=5s max_fails=1;server 10.0.0.1 fail_timeout=5s max_fails=1; server 10.0.0.2 fail_timeout=5s max_fails=1;server 10.0.0.2 fail_timeout=5s max_fails=1; keepalive 512;keepalive 512; }}
  • 11. Load balancing with NginxLoad balancing with Nginx weight=numberweight=number max_fails=numbermax_fails=number fail_timeout=timefail_timeout=time backupbackup downdown max_conns=numbermax_conns=number resolveresolve slow_start=timeslow_start=time
  • 12. Load balancing with NginxLoad balancing with Nginx Request distribution methodRequest distribution method ➢ round-robin (default)round-robin (default) ➢ ip_haship_hash ➢ hashhash ➢ least_connleast_conn ➢ least_timeleast_time header/bytesheader/bytes
  • 13. Load balancing with NginxLoad balancing with Nginx keepalivekeepalive health_check [parameters]health_check [parameters] match namematch name queue number [timeout=time]queue number [timeout=time] sticky cookie namesticky cookie name
  • 14. Load balancing with NginxLoad balancing with Nginx health_check interval=1 uri=/health;health_check interval=1 uri=/health; # status ok and not in maintenance mode# status ok and not in maintenance mode match server_ok {match server_ok { status 200-399;status 200-399; body !~ "maintenance mode";body !~ "maintenance mode"; }}
  • 15. Caching in NginxCaching in Nginx ➢ Why not cache the static content?Why not cache the static content? ➢ Limited ESI support troughLimited ESI support trough ngx_http_ssi and ngx_esingx_http_ssi and ngx_esi ➢ Handle traffic extremesHandle traffic extremes withwith stale cachingstale caching ➢ Reduce response timesReduce response times If there are people willing to extend ngx_esiIf there are people willing to extend ngx_esi I would join forces with them!I would join forces with them!
  • 16. Caching in NginxCaching in Nginx proxy_cache_path /var/lib/nginx/cacheproxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=WP:1024mlevels=1:2 keys_zone=WP:1024m max_size=2048m;max_size=2048m; proxy_cache_keyproxy_cache_key "$host$request_uri $cookie_user";"$host$request_uri $cookie_user"; proxy_cache_valid 200 301 302 2s;proxy_cache_valid 200 301 302 2s; proxy_cache_use_staleproxy_cache_use_stale error timeout invalid_header updating;error timeout invalid_header updating; expires 60s;expires 60s;
  • 17. ?/? Questions ?/??/? Questions ?/? MarianMarian HackManHackMan MarinovMarinov <mm@1h.com><mm@1h.com> CEO of 1H Ltd.CEO of 1H Ltd.