SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
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!!!

Contenu connexe

Tendances

Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web serverMd Waresul Islam
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
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.
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
 
Docker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshopDocker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshopSathish VJ
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90minsLarry Cai
 
[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용NAVER D2
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationKumar Y
 
NGINX Ingress Controller for Kubernetes
NGINX Ingress Controller for KubernetesNGINX Ingress Controller for Kubernetes
NGINX Ingress Controller for KubernetesNGINX, Inc.
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 
Kubernetes #4 volume &amp; stateful set
Kubernetes #4   volume &amp; stateful setKubernetes #4   volume &amp; stateful set
Kubernetes #4 volume &amp; stateful setTerry Cho
 
Kubernetes dealing with storage and persistence
Kubernetes  dealing with storage and persistenceKubernetes  dealing with storage and persistence
Kubernetes dealing with storage and persistenceJanakiram MSV
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX, Inc.
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육Ji-Woong Choi
 

Tendances (20)

Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web server
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
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
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
Docker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshopDocker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshop
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
Nginx
NginxNginx
Nginx
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용
 
Nginx
NginxNginx
Nginx
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
NGINX Ingress Controller for Kubernetes
NGINX Ingress Controller for KubernetesNGINX Ingress Controller for Kubernetes
NGINX Ingress Controller for Kubernetes
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Kubernetes #4 volume &amp; stateful set
Kubernetes #4   volume &amp; stateful setKubernetes #4   volume &amp; stateful set
Kubernetes #4 volume &amp; stateful set
 
Kubernetes dealing with storage and persistence
Kubernetes  dealing with storage and persistenceKubernetes  dealing with storage and persistence
Kubernetes dealing with storage and persistence
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육
[오픈소스컨설팅] Ansible을 활용한 운영 자동화 교육
 

En vedette

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
 

En vedette (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
 

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

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

Plus de Marian Marinov

How to implement PassKeys in your application
How to implement PassKeys in your applicationHow to implement PassKeys in your application
How to implement PassKeys in your applicationMarian 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
 

Plus de Marian Marinov (20)

How to implement PassKeys in your application
How to implement PassKeys in your applicationHow to implement PassKeys in your application
How to implement PassKeys in your application
 
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
 

Dernier

20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolinonuriaiuzzolino1
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 

Dernier (20)

20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 

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.