SlideShare a Scribd company logo
1 of 24
Nginx - Tips & Tricks
       #rootconf
       May 2012
        @tuxtoti
/me

Builds scalable systems for ADIQUITY

Works with web servers/load balancers

Identify bottlenecks in the architecture.

Responsible for smooth serving of Mobile
Ads.
Nginx - History
circa 2002. Igor Sysoev. Russian dev.

writes mod_accel. Realizes the Apache’s low
scalability.

2004 - powers rambler.ru. Initial public
version released.

was built to address the C10K problem

Now after ~10 yrs its Nginx Inc.
Nginx - C10K problem


To serve concurrent 10K connections

Why? I/O is the bottleneck. A thread per
connection model fails. #apachefail

select() vs epoll()

http://www.kegel.com/c10k.html
Nginx - Killer Features

 L7 Load Balancer/Reverse proxy

 Embedded perl interpreter

 On the fly binary upgrade.

 Awesome PCRE support. Useful for rewriting
 URLs.

 NGINX - Ultra-fast, Light weight, low
 memory footprint, feature rich
Nginx - Config Contexts
 http - The main scope . Typically configs set
 here will reflect everywhere.

 server - The to run multiple servers virtually
 on different ports or with different server
 names.

 location - Defines the scope for a URI.

 upstream - Config scope for a set of
 upstream/backend servers.
Nginx - Directives
worker_processes, worker_connections,
worker_rlimit_nofile - Configure your setup
to the amount of traffic you expect to
receive.

Number of connections =
worker_processes*worker_connections

keepalive_requests, keepalive_timeout -
Configure based on your concurrency and
throughput.
Nginx - Directives
 upstream - Set up a list of backends for load
 balancing. W/ rr and wrr it becomes very
 powerful. max_fails & fail_timeout - to
 consider a backend inoperative.
upstream backend {
  server 192.168.1.1;
  server 192.168.1.5:8080;
  server 192.168.1.13 weight=3;
  server 192.168.1.16 max_fails=3 fail_timeout=10s;
  keepalive 2048; #nginx > 1.1.4
}

server {
  location / {
    proxy_pass http://backend;
  }
}
Nginx - Directives
rr vs fair - Send the request to the least
busy backend server. #Available as a third
party module
 upstream backend {
   fair;
   server 192.168.1.2;
   server 192.168.1.3;
 }

fair - knows how many requests each
backend is processing.

no_rr
Nginx - Directives
proxy_next_upstream - To proceed or to not
proceed?

location ~ ^/(app) {
	 	 	 proxy_read_timeout 12;
	 	 	 proxy_set_header X-Feature-Foo “1”;

	 	 	 proxy_pass http://test_backend;
	 	 	 proxy_next_upstream error;
}

  Takes values: error, timeout, invalid_header,
  http_*, off
Nginx - Directives
 add_header - Add custom headers to the
 response. #USE - Debug to find out the
 backend server / cache control headers.

add_header   Cache-Control   private;



proxy_set_header - Add custom headers to
control your backends. #USE - for enabling/
disabling features in your backend.
Nginx - Directives
  empty_gif - Serves a 1x1 transparent gif
  from memory. #USE - for dropping beacons/
  pixels

location = /beacon {
        empty_gif;
}
Nginx - Directives

limit_req_zone - Throttle the frequency of
requests for a client. #USE - mitigate DOS
attacks.

http {
    limit_req_zone $binary_remote_addr
zone=one:10m    rate=1r/s;
     ...
    server {
       ...
           location /search/ {
                  limit_req    zone=one burst=4;
           }
Nginx - Directives
limit_conn_zone - Throttle concurrency of
connections for a client.

http {
        limit_conn_zone     $binary_remote_addr
zone=one:2m;

         server {
                    location /download {
                            limit_conn one   1;
                    }
         }
}
Nginx - Directives
 stub_status - To get the current status of
 nginx. #USE - gives you info like the curr.
 active conn., total conn. accepted and
 handled, current no. of read/write/wait conn.

location /ngx_stat {
        stub_status on;
        access_log   off;
}

Active connections: 291
server accepts handled requests
  16630948 16630948 31070465
  Reading: 6 Writing: 179 Waiting: 106
Nginx - Directives
    map - To map a set of values to a different
    set of values. #USE - for dynamically
    changing hosts based on URIs.

map $uri $new {
        default http://www.domain.com/home/;

           /aa     http://aa.domain.com/;
           /bb     http://bb.domain.com/;
           /john   http://my.domain.com/users/john/;
}

server {
           server_name   www.domain.com;
           rewrite ^$new    redirect;
}
Nginx - Directives
 split_clients - To split clients based on some
 conditions. #USE - for A/B testing in
 variation in colors/designs.


http {
         split_clients "${remote_addr}" $variant {
                 0.5% .one;
                 2.0% .two;
                 - "";
         }

         server {
                    location / {
                            index index${variant}.html;
Nginx - Directives

sub_filter - Search and replace content in
the response. #USE - Quick fix for stale
data/ typos?

error_pages - Custom error pages for your
#failwhale moments.

if/set/rewrite - powerful constructs for
condition based execution.
Nginx - Builtin Variables


 $arg_PARAM - To read the value of a GET
 request PARAM.

 $http_HEADER - To read the value of any
 request HEADER.
Nginx - Builtin Variables


 $request_time - Measure end to end time.
 #caveat - only from read() to write()/
 sendfile()

 $upstream_response_time - Measure end to
 end time of your upstream server (w/
 $upstream_addr)
Nginx - Modules
Embedded Perl - To execute perl directly
inside nginx.

XSLT - Transform your XML responses to
HTML in nginx.

FLV/MP4 - To stream FLV/MP4 content.

Addition - To add content of other locations
to the current location.

GeoIP/Mail/Image Filter/Memcached modules
Nginx - Woes


No dynamically loadable modules yet.

Sparse/Bad documentation. (though better
now)
Nginx - Awesomeness


Vibrant community.

Very helpful for novices.

Active IRC/Mailing list
Q?

Thanks !
 @tuxtoti

More Related Content

What's hot

NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX, Inc.
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX, Inc.
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90minsLarry Cai
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance CachingNGINX, Inc.
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyNginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyAmit Aggarwal
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
What's New in NGINX Plus R12?
What's New in NGINX Plus R12? What's New in NGINX Plus R12?
What's New in NGINX Plus R12? NGINX, Inc.
 
Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web serverMd Waresul Islam
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx InternalsJoshua Zhu
 
Lcu14 Lightning Talk- NGINX
Lcu14 Lightning Talk- NGINXLcu14 Lightning Talk- NGINX
Lcu14 Lightning Talk- NGINXLinaro
 
Maximizing PHP Performance with NGINX
Maximizing PHP Performance with NGINXMaximizing PHP Performance with NGINX
Maximizing PHP Performance with NGINXNGINX, Inc.
 
under the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lessunder the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lesssarahnovotny
 
Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to NginxKnoldus Inc.
 
Load Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS ClusterLoad Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS ClusterKevin Jones
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusNGINX, Inc.
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!Jeff Anderson
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusKevin Jones
 

What's hot (20)

Nginx
NginxNginx
Nginx
 
NGINX: High Performance Load Balancing
NGINX: High Performance Load BalancingNGINX: High Performance Load Balancing
NGINX: High Performance Load Balancing
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
Nginx Essential
Nginx EssentialNginx Essential
Nginx Essential
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance Caching
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse ProxyNginx A High Performance Load Balancer, Web Server & Reverse Proxy
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
 
Nginx dhruba mandal
Nginx dhruba mandalNginx dhruba mandal
Nginx dhruba mandal
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
What's New in NGINX Plus R12?
What's New in NGINX Plus R12? What's New in NGINX Plus R12?
What's New in NGINX Plus R12?
 
Introduction to NGINX web server
Introduction to NGINX web serverIntroduction to NGINX web server
Introduction to NGINX web server
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
Lcu14 Lightning Talk- NGINX
Lcu14 Lightning Talk- NGINXLcu14 Lightning Talk- NGINX
Lcu14 Lightning Talk- NGINX
 
Maximizing PHP Performance with NGINX
Maximizing PHP Performance with NGINXMaximizing PHP Performance with NGINX
Maximizing PHP Performance with NGINX
 
under the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or lessunder the covers -- chef in 20 minutes or less
under the covers -- chef in 20 minutes or less
 
Introduction to Nginx
Introduction to NginxIntroduction to Nginx
Introduction to Nginx
 
Load Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS ClusterLoad Balancing Applications with NGINX in a CoreOS Cluster
Load Balancing Applications with NGINX in a CoreOS Cluster
 
Rate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX PlusRate Limiting with NGINX and NGINX Plus
Rate Limiting with NGINX and NGINX Plus
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX Plus
 

Similar to Nginx - Tips and Tricks.

Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisationgrooverdan
 
Running Node.js in Production using Passenger
Running Node.js in Production using PassengerRunning Node.js in Production using Passenger
Running Node.js in Production using Passengerdavidchubbs
 
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...addame
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesOrtus Solutions, Corp
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talkLocaweb
 
Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic OperationSimon Su
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginxVmoksha Admin
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Container Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeContainer Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeDocker, Inc.
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practiceDocker, Inc.
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkJulien SIMON
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with NginxBud Siddhisena
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
LAB - Perforce Large Scale & Multi-Site Implementations
LAB - Perforce Large Scale & Multi-Site ImplementationsLAB - Perforce Large Scale & Multi-Site Implementations
LAB - Perforce Large Scale & Multi-Site ImplementationsPerforce
 
[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure[MathWorks] Versioning Infrastructure
[MathWorks] Versioning InfrastructurePerforce
 
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...MariaDB Corporation
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...BIOVIA
 

Similar to Nginx - Tips and Tricks. (20)

Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
Running Node.js in Production using Passenger
Running Node.js in Production using PassengerRunning Node.js in Production using Passenger
Running Node.js in Production using Passenger
 
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluste...
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 
Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic Operation
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginx
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Container Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeContainer Orchestration from Theory to Practice
Container Orchestration from Theory to Practice
 
Container orchestration from theory to practice
Container orchestration from theory to practiceContainer orchestration from theory to practice
Container orchestration from theory to practice
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalk
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
LAB - Perforce Large Scale & Multi-Site Implementations
LAB - Perforce Large Scale & Multi-Site ImplementationsLAB - Perforce Large Scale & Multi-Site Implementations
LAB - Perforce Large Scale & Multi-Site Implementations
 
Apache
ApacheApache
Apache
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure
 
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...
Skalierbarkeit mit MariaDB und MaxScale - MariaDB Roadshow Summer 2014 Hambur...
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
 

Recently uploaded

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Nginx - Tips and Tricks.

  • 1. Nginx - Tips & Tricks #rootconf May 2012 @tuxtoti
  • 2. /me Builds scalable systems for ADIQUITY Works with web servers/load balancers Identify bottlenecks in the architecture. Responsible for smooth serving of Mobile Ads.
  • 3. Nginx - History circa 2002. Igor Sysoev. Russian dev. writes mod_accel. Realizes the Apache’s low scalability. 2004 - powers rambler.ru. Initial public version released. was built to address the C10K problem Now after ~10 yrs its Nginx Inc.
  • 4. Nginx - C10K problem To serve concurrent 10K connections Why? I/O is the bottleneck. A thread per connection model fails. #apachefail select() vs epoll() http://www.kegel.com/c10k.html
  • 5. Nginx - Killer Features L7 Load Balancer/Reverse proxy Embedded perl interpreter On the fly binary upgrade. Awesome PCRE support. Useful for rewriting URLs. NGINX - Ultra-fast, Light weight, low memory footprint, feature rich
  • 6. Nginx - Config Contexts http - The main scope . Typically configs set here will reflect everywhere. server - The to run multiple servers virtually on different ports or with different server names. location - Defines the scope for a URI. upstream - Config scope for a set of upstream/backend servers.
  • 7. Nginx - Directives worker_processes, worker_connections, worker_rlimit_nofile - Configure your setup to the amount of traffic you expect to receive. Number of connections = worker_processes*worker_connections keepalive_requests, keepalive_timeout - Configure based on your concurrency and throughput.
  • 8. Nginx - Directives upstream - Set up a list of backends for load balancing. W/ rr and wrr it becomes very powerful. max_fails & fail_timeout - to consider a backend inoperative. upstream backend { server 192.168.1.1; server 192.168.1.5:8080; server 192.168.1.13 weight=3; server 192.168.1.16 max_fails=3 fail_timeout=10s; keepalive 2048; #nginx > 1.1.4 } server { location / { proxy_pass http://backend; } }
  • 9. Nginx - Directives rr vs fair - Send the request to the least busy backend server. #Available as a third party module upstream backend { fair; server 192.168.1.2; server 192.168.1.3; } fair - knows how many requests each backend is processing. no_rr
  • 10. Nginx - Directives proxy_next_upstream - To proceed or to not proceed? location ~ ^/(app) { proxy_read_timeout 12; proxy_set_header X-Feature-Foo “1”; proxy_pass http://test_backend; proxy_next_upstream error; } Takes values: error, timeout, invalid_header, http_*, off
  • 11. Nginx - Directives add_header - Add custom headers to the response. #USE - Debug to find out the backend server / cache control headers. add_header Cache-Control private; proxy_set_header - Add custom headers to control your backends. #USE - for enabling/ disabling features in your backend.
  • 12. Nginx - Directives empty_gif - Serves a 1x1 transparent gif from memory. #USE - for dropping beacons/ pixels location = /beacon { empty_gif; }
  • 13. Nginx - Directives limit_req_zone - Throttle the frequency of requests for a client. #USE - mitigate DOS attacks. http { limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; ... server { ... location /search/ { limit_req zone=one burst=4; }
  • 14. Nginx - Directives limit_conn_zone - Throttle concurrency of connections for a client. http { limit_conn_zone $binary_remote_addr zone=one:2m; server { location /download { limit_conn one 1; } } }
  • 15. Nginx - Directives stub_status - To get the current status of nginx. #USE - gives you info like the curr. active conn., total conn. accepted and handled, current no. of read/write/wait conn. location /ngx_stat { stub_status on; access_log off; } Active connections: 291 server accepts handled requests 16630948 16630948 31070465 Reading: 6 Writing: 179 Waiting: 106
  • 16. Nginx - Directives map - To map a set of values to a different set of values. #USE - for dynamically changing hosts based on URIs. map $uri $new { default http://www.domain.com/home/; /aa http://aa.domain.com/; /bb http://bb.domain.com/; /john http://my.domain.com/users/john/; } server { server_name www.domain.com; rewrite ^$new redirect; }
  • 17. Nginx - Directives split_clients - To split clients based on some conditions. #USE - for A/B testing in variation in colors/designs. http { split_clients "${remote_addr}" $variant { 0.5% .one; 2.0% .two; - ""; } server { location / { index index${variant}.html;
  • 18. Nginx - Directives sub_filter - Search and replace content in the response. #USE - Quick fix for stale data/ typos? error_pages - Custom error pages for your #failwhale moments. if/set/rewrite - powerful constructs for condition based execution.
  • 19. Nginx - Builtin Variables $arg_PARAM - To read the value of a GET request PARAM. $http_HEADER - To read the value of any request HEADER.
  • 20. Nginx - Builtin Variables $request_time - Measure end to end time. #caveat - only from read() to write()/ sendfile() $upstream_response_time - Measure end to end time of your upstream server (w/ $upstream_addr)
  • 21. Nginx - Modules Embedded Perl - To execute perl directly inside nginx. XSLT - Transform your XML responses to HTML in nginx. FLV/MP4 - To stream FLV/MP4 content. Addition - To add content of other locations to the current location. GeoIP/Mail/Image Filter/Memcached modules
  • 22. Nginx - Woes No dynamically loadable modules yet. Sparse/Bad documentation. (though better now)
  • 23. Nginx - Awesomeness Vibrant community. Very helpful for novices. Active IRC/Mailing list

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n