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

Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to NginxKnoldus Inc.
 
Percona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsPercona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsMydbops
 
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.
 
Let's Compare: A Benchmark review of InfluxDB and Elasticsearch
Let's Compare: A Benchmark review of InfluxDB and ElasticsearchLet's Compare: A Benchmark review of InfluxDB and Elasticsearch
Let's Compare: A Benchmark review of InfluxDB and ElasticsearchInfluxData
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXNGINX, Inc.
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX, Inc.
 
Autoscaling Flink with Reactive Mode
Autoscaling Flink with Reactive ModeAutoscaling Flink with Reactive Mode
Autoscaling Flink with Reactive ModeFlink Forward
 
5 things you didn't know nginx could do
5 things you didn't know nginx could do5 things you didn't know nginx could do
5 things you didn't know nginx could dosarahnovotny
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker IntroductionRobert Reiz
 
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)Brian Brazil
 
Web servers presentacion
Web servers presentacionWeb servers presentacion
Web servers presentacionKiwi Science
 
Nginx internals
Nginx internalsNginx internals
Nginx internalsliqiang xu
 
2021.laravelconf.tw.slides5
2021.laravelconf.tw.slides52021.laravelconf.tw.slides5
2021.laravelconf.tw.slides5LiviaLiaoFontech
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 
Using the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production DeploymentUsing the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production DeploymentFlink Forward
 

What's hot (20)

Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to Nginx
 
Nginx Essential
Nginx EssentialNginx Essential
Nginx Essential
 
Percona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient BackupsPercona Xtrabackup - Highly Efficient Backups
Percona Xtrabackup - Highly Efficient Backups
 
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
 
Let's Compare: A Benchmark review of InfluxDB and Elasticsearch
Let's Compare: A Benchmark review of InfluxDB and ElasticsearchLet's Compare: A Benchmark review of InfluxDB and Elasticsearch
Let's Compare: A Benchmark review of InfluxDB and Elasticsearch
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINX
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
Nginx
NginxNginx
Nginx
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
Autoscaling Flink with Reactive Mode
Autoscaling Flink with Reactive ModeAutoscaling Flink with Reactive Mode
Autoscaling Flink with Reactive Mode
 
5 things you didn't know nginx could do
5 things you didn't know nginx could do5 things you didn't know nginx could do
5 things you didn't know nginx could do
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
 
Web servers presentacion
Web servers presentacionWeb servers presentacion
Web servers presentacion
 
Nginx internals
Nginx internalsNginx internals
Nginx internals
 
2021.laravelconf.tw.slides5
2021.laravelconf.tw.slides52021.laravelconf.tw.slides5
2021.laravelconf.tw.slides5
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
HAProxy 1.9
HAProxy 1.9HAProxy 1.9
HAProxy 1.9
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
Using the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production DeploymentUsing the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production Deployment
 

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
 
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 (7)

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
 
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

Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdfkeithzhangding
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneCall girls in Ahmedabad High profile
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 

Recently uploaded (20)

Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
象限策略:Google Workspace 与 Microsoft 365 对业务的影响 .pdf
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Vip Call Girls Aerocity ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Aerocity ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Aerocity ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Aerocity ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 

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.