SlideShare une entreprise Scribd logo
1  sur  35
Avoiding Common NGINX
Configuration Mistakes
Robert Haynes, Timo Stark
NGINX
©2022 F5
2
1. Not setting enough file
descriptors
©2022 F5
3
File Descriptors?
• Everything in UNIX/LINUX is a file (sort of)
• Each process (e.g. an NGINX worker process) needs a file descriptor for:
• Standard input and standard error
• Every file that a process opens
• Every network socket
• Some system calls
©2022 F5
4
Example
lrwx------ 1 nginx nginx 64 Jul 11 16:55 0 -> /dev/null
lrwx------ 1 nginx nginx 64 Jul 11 16:55 1 -> /dev/null
lrwx------ 1 nginx nginx 64 Jul 11 16:55 10 -> 'anon_inode:[eventpoll]'
lrwx------ 1 nginx nginx 64 Jul 11 16:55 11 -> 'anon_inode:[eventfd]'
lrwx------ 1 nginx nginx 64 Jul 11 16:55 12 -> 'anon_inode:[eventfd]'
l-wx------ 1 nginx nginx 64 Jul 11 16:55 2 -> /var/log/nginx/error.log
l-wx------ 1 nginx nginx 64 Jul 11 16:55 3 -> /var/log/nginx/error.log
l-wx------ 1 nginx nginx 64 Jul 11 16:55 4 -> /var/log/nginx/access.log
lrwx------ 1 nginx nginx 64 Jul 11 16:55 6 -> 'socket:[52276]'
lrwx------ 1 nginx nginx 64 Jul 11 16:55 7 -> 'socket:[7717086]'
ls –l /proc/<NGINX worker process id>/fd
Will increase with the number of connections
©2022 F5
5
What happens if you run out?
root@ip-10-0-1-4:/proc/6179/fdinfo# tail -f
/var/log/nginx/error.log
2022/07/18 16:22:22 [alert] 1485851#1485851: *183 socket()
failed (24: Too many open files) while connecting to upstream,
client: 71.197.217.65, server: www.snarketing.net, request:
"GET / HTTP/1.1", upstream: "http://10.0.1.199:8082/", host:
"www.snarketing.net"
.net"
Application errors
Error log entries
©2022 F5
6
How many do you need?
NGINX Worker
Client
Connection
Upstream
Servers
Log Files
Number of connections
per worker is set by the
worker_connections
directive (default 512)
but example configs are
set at 1024.
Each connection to an
upstream server needs 1
file descriptor, plus some
for response caching
Writing to log files also
require a file descriptor
A good baseline is to set max file handles to
2 X worker_connections (OS default is
usually 1024)
©2022 F5
7
Increasing file descriptors
Add the worker_rlimit_nofile directive to the main{} context
user nginx;
worker_processes 1024;
worker_rlimit_nofile 2048;
error_log /var/log/nginx/error.log
notice;
pid /var/run/nginx.pid;
©2022 F5
8
Demo
Audience Participation Required!
©2022 F5
9
2. Root Only inside Location
Blocks
©2022 F5
10
Document Roots and Location Blocks
root <path>;
location <url> {
# do something
}
Sets the location to look for files to
serve
Defines some actions to take based on
the url (regex/wildcard ok)
©2022 F5
11
Our Directory Structure
.
└── html
├── 50x.html
├── dashboard.html
├── images
│ ├── cat.jpg
│ ├── credits.txt
│ ├── ostrich.jpg
│ └── potato.jpg
├── index.html
├── mammal
│ └── cat
│ └── index.html
├── nginx-modules-reference.pdf
├── ostrich
│ └── index.html
└── veg
└── potato
└── index.html
©2022 F5
12
Our config file:
server {
listen 80 default_server;
server_name www.snarketing.net;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /cat {
root /usr/share/nginx/html/mammal;
}
location /potato {
root /usr/share/nginx/html/veg;
}
…
}
©2022 F5
13
Example
location /cat {
root /usr/share/nginx/html/mammal;
}
├── mammal
└── cat
└── index.html
Not Secure | http://www.snarketing.net/cat
©2022 F5
14
What if?
location /ostrich {
proxy_set_header foo "test";
}
©2022 F5
15
Solution
server {
listen 80 default_server;
server_name www.snarketing.net;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /cat {
root /usr/share/nginx/html/mammal;
}
location /potato {
root /usr/share/nginx/html/veg;
}
…
root /usr/share/nginx/html;
©2022 F5
16
Demo
©2022 F5
17
3. Using ‘if’ in a location
context
©2022 F5
18
“Directive if has problems when used in location
context, in some cases it doesn’t do what you
expect but something completely different instead.
In some cases it even segfaults. It’s generally a
good idea to avoid it if possible.”
©2022 F5
19
• Usually computationally more expensive than an in-built function
• Takes a deep understanding of how if executes in the NGINX rewrite module to
avoid problems (NGINX 301?)
• Can cause an NGINX SIGSEV (bad)
Reasons not to use “if” in a location Context
©2022 F5
20
Example: Don’t use if to check for a file
server {
listen 80 default_server;
server_name www.snarketing.net;
access_log /var/log/nginx/host.access.log main;
index index.html index.htm;
root /usr/share/nginx/html;
location / {
if (!-f $request_filename) {
break;
}
}
…
©2022 F5
21
Use try_files instead
server {
listen 80 default_server;
server_name www.snarketing.net;
access_log /var/log/nginx/host.access.log main;
index index.html index.htm;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
}
©2022 F5
22
Demo
©2022 F5
23
4. Directive Inheritance
Confusion
©2022 F5
24
Directives are inherited ”outside in”
http {
server {
location foo {
root /home/user/public_html;
}
}
}
root /home/user/foo;
Sets directive
Inherits Directive
Overrides directive
©2022 F5
25
Array type directives can have multiple values – the most common example is add_header
Beware of array-type Directives
location / {
add_header My-Header 1;
add_header My-Other-Header 2;
add_header My-Other-Othe-Header 3;
}
You might think that inheritance would work by adding the headers together
server {
…
add_header My-Header 1;
location / {
add_header My-Other-Header 2;
}
But you would be wrong!
©2022 F5
26
Example: add_header
http {
add_header X-HTTP-LEVEL-HEADER 1;
add_header X-ANOTHER-HTTP-LEVEL-HEADER 1;
server {
listen 8080;
location / {
return 200 "OK";
}
}
server {
listen 8081;
add_header X-SERVER-LEVEL-HEADER 1;
location / {
return 200 "OK";
}
location /test {
add_header X-LOCATION-LEVEL-HEADER 1;
return 200 "OK";
}
location /correct {
add_header X-HTTP-LEVEL-HEADER 1;
add_header X-ANOTHER-HTTP-LEVEL-HEADER 1;
add_header X-SERVER-LEVEL-HEADER 1;
add_header X-LOCATION-LEVEL-HEADER 1;
return 200 "OK";
}
}
Inherits
Replaces
Replaces
To get all headers must
duplicate
©2022 F5
27
Demo
©2022 F5
28
5. Not Using Keepalives
for upstreams
©2022 F5
29
What are keepalives and why should you care?
Upstreams
Clients
Without keepalives NGINX
opens a new connection for
each HTTP request
Ephemeral port
exhaustion
©2022 F5
30
What are keepalives and why should you care?
Upstreams
Clients
With keepalives NGINX
reuses connections to
upstreams
©2022 F5
31
Demo
©2022 F5
32
Use the keepalive directive in the upstream{} block
Enabling keepalives
upstream http_backend {
server 127.0.0.1:8080;
keepalive 4;
}
This ensures that the connection uses the correct
HTTP version (HTTP 1 does not support
keepalives)
Add the following directives to the location{} block
location / {
proxy_http_version 1.1;
proxy_set_header "Connection" "";
proxy_pass http://backend;
}
What number to set the keepalive value to?
We recommend at least 4 x the number of servers
listed in the upstream{} block.
©2022 F5
33
Demo
©2022 F5
34
Questions?
Top 5 NGINX Configuration Mistakes to Avoid

Contenu connexe

Similaire à Top 5 NGINX Configuration Mistakes to Avoid

NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more DockerSarah Novotny
 
NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)Marcel Cattaneo
 
Managing and Monitoring Application Performance
Managing and Monitoring Application PerformanceManaging and Monitoring Application Performance
Managing and Monitoring Application PerformanceSebastian Marek
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXNGINX, Inc.
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetupNicole Johnson
 
Infrastructure as code with Docker and fig
Infrastructure as code with Docker and figInfrastructure as code with Docker and fig
Infrastructure as code with Docker and figpranas_algoteq
 
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
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleRobert Reiz
 
Known basic of NFV Features
Known basic of NFV FeaturesKnown basic of NFV Features
Known basic of NFV FeaturesRaul Leite
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
MySQL | My SQL docker containerization | Docker Network
MySQL | My SQL docker containerization | Docker NetworkMySQL | My SQL docker containerization | Docker Network
MySQL | My SQL docker containerization | Docker Networkshrenikp
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXKevin Jones
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAkshaya Mahapatra
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Rich Bowen
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios
 
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryRevolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryImesh Gunaratne
 
桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作Philip Zheng
 

Similaire à Top 5 NGINX Configuration Mistakes to Avoid (20)

NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
 
NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)
 
Managing and Monitoring Application Performance
Managing and Monitoring Application PerformanceManaging and Monitoring Application Performance
Managing and Monitoring Application Performance
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Philly security shell meetup
Philly security shell meetupPhilly security shell meetup
Philly security shell meetup
 
Infrastructure as code with Docker and fig
Infrastructure as code with Docker and figInfrastructure as code with Docker and fig
Infrastructure as code with Docker and fig
 
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
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & Ansible
 
Known basic of NFV Features
Known basic of NFV FeaturesKnown basic of NFV Features
Known basic of NFV Features
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
MySQL | My SQL docker containerization | Docker Network
MySQL | My SQL docker containerization | Docker NetworkMySQL | My SQL docker containerization | Docker Network
MySQL | My SQL docker containerization | Docker Network
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
 
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryRevolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
 
桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作桃園市教育局Docker技術入門與實作
桃園市教育局Docker技術入門與實作
 

Plus de NGINX, Inc.

【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法NGINX, Inc.
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナーNGINX, Inc.
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法NGINX, Inc.
 
Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3NGINX, Inc.
 
Managing Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & KubecostManaging Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & KubecostNGINX, Inc.
 
Manage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with ObservabilityManage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with ObservabilityNGINX, Inc.
 
Accelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with AutomationAccelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with AutomationNGINX, Inc.
 
Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101NGINX, Inc.
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesUnit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesNGINX, Inc.
 
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!NGINX, Inc.
 
Easily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINXEasily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINXNGINX, Inc.
 
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!NGINX, Inc.
 
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINXKeep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINXNGINX, Inc.
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...NGINX, Inc.
 
Protecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINXProtecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINXNGINX, Inc.
 
NGINX Kubernetes API
NGINX Kubernetes APINGINX Kubernetes API
NGINX Kubernetes APINGINX, Inc.
 
Successfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINXSuccessfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINXNGINX, Inc.
 
Installing and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceInstalling and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceNGINX, Inc.
 
Shift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINXShift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINXNGINX, Inc.
 
Kubernetes環境で実現するWebアプリケーションセキュリティ
Kubernetes環境で実現するWebアプリケーションセキュリティKubernetes環境で実現するWebアプリケーションセキュリティ
Kubernetes環境で実現するWebアプリケーションセキュリティNGINX, Inc.
 

Plus de NGINX, Inc. (20)

【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
 
Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3Get Hands-On with NGINX and QUIC+HTTP/3
Get Hands-On with NGINX and QUIC+HTTP/3
 
Managing Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & KubecostManaging Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & Kubecost
 
Manage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with ObservabilityManage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with Observability
 
Accelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with AutomationAccelerate Microservices Deployments with Automation
Accelerate Microservices Deployments with Automation
 
Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101Unit 2: Microservices Secrets Management 101
Unit 2: Microservices Secrets Management 101
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices ArchitecturesUnit 1: Apply the Twelve-Factor App to Microservices Architectures
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
 
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
 
Easily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINXEasily View, Manage, and Scale Your App Security with F5 NGINX
Easily View, Manage, and Scale Your App Security with F5 NGINX
 
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
NGINXセミナー(基本編)~いまさら聞けないNGINXコンフィグなど基本がわかる!
 
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINXKeep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
Keep Ahead of Evolving Cyberattacks with OPSWAT and F5 NGINX
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
 
Protecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINXProtecting Apps from Hacks in Kubernetes with NGINX
Protecting Apps from Hacks in Kubernetes with NGINX
 
NGINX Kubernetes API
NGINX Kubernetes APINGINX Kubernetes API
NGINX Kubernetes API
 
Successfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINXSuccessfully Implement Your API Strategy with NGINX
Successfully Implement Your API Strategy with NGINX
 
Installing and Configuring NGINX Open Source
Installing and Configuring NGINX Open SourceInstalling and Configuring NGINX Open Source
Installing and Configuring NGINX Open Source
 
Shift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINXShift Left for More Secure Apps with F5 NGINX
Shift Left for More Secure Apps with F5 NGINX
 
Kubernetes環境で実現するWebアプリケーションセキュリティ
Kubernetes環境で実現するWebアプリケーションセキュリティKubernetes環境で実現するWebアプリケーションセキュリティ
Kubernetes環境で実現するWebアプリケーションセキュリティ
 

Dernier

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Dernier (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

Top 5 NGINX Configuration Mistakes to Avoid

  • 1. Avoiding Common NGINX Configuration Mistakes Robert Haynes, Timo Stark NGINX
  • 2. ©2022 F5 2 1. Not setting enough file descriptors
  • 3. ©2022 F5 3 File Descriptors? • Everything in UNIX/LINUX is a file (sort of) • Each process (e.g. an NGINX worker process) needs a file descriptor for: • Standard input and standard error • Every file that a process opens • Every network socket • Some system calls
  • 4. ©2022 F5 4 Example lrwx------ 1 nginx nginx 64 Jul 11 16:55 0 -> /dev/null lrwx------ 1 nginx nginx 64 Jul 11 16:55 1 -> /dev/null lrwx------ 1 nginx nginx 64 Jul 11 16:55 10 -> 'anon_inode:[eventpoll]' lrwx------ 1 nginx nginx 64 Jul 11 16:55 11 -> 'anon_inode:[eventfd]' lrwx------ 1 nginx nginx 64 Jul 11 16:55 12 -> 'anon_inode:[eventfd]' l-wx------ 1 nginx nginx 64 Jul 11 16:55 2 -> /var/log/nginx/error.log l-wx------ 1 nginx nginx 64 Jul 11 16:55 3 -> /var/log/nginx/error.log l-wx------ 1 nginx nginx 64 Jul 11 16:55 4 -> /var/log/nginx/access.log lrwx------ 1 nginx nginx 64 Jul 11 16:55 6 -> 'socket:[52276]' lrwx------ 1 nginx nginx 64 Jul 11 16:55 7 -> 'socket:[7717086]' ls –l /proc/<NGINX worker process id>/fd Will increase with the number of connections
  • 5. ©2022 F5 5 What happens if you run out? root@ip-10-0-1-4:/proc/6179/fdinfo# tail -f /var/log/nginx/error.log 2022/07/18 16:22:22 [alert] 1485851#1485851: *183 socket() failed (24: Too many open files) while connecting to upstream, client: 71.197.217.65, server: www.snarketing.net, request: "GET / HTTP/1.1", upstream: "http://10.0.1.199:8082/", host: "www.snarketing.net" .net" Application errors Error log entries
  • 6. ©2022 F5 6 How many do you need? NGINX Worker Client Connection Upstream Servers Log Files Number of connections per worker is set by the worker_connections directive (default 512) but example configs are set at 1024. Each connection to an upstream server needs 1 file descriptor, plus some for response caching Writing to log files also require a file descriptor A good baseline is to set max file handles to 2 X worker_connections (OS default is usually 1024)
  • 7. ©2022 F5 7 Increasing file descriptors Add the worker_rlimit_nofile directive to the main{} context user nginx; worker_processes 1024; worker_rlimit_nofile 2048; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid;
  • 9. ©2022 F5 9 2. Root Only inside Location Blocks
  • 10. ©2022 F5 10 Document Roots and Location Blocks root <path>; location <url> { # do something } Sets the location to look for files to serve Defines some actions to take based on the url (regex/wildcard ok)
  • 11. ©2022 F5 11 Our Directory Structure . └── html ├── 50x.html ├── dashboard.html ├── images │ ├── cat.jpg │ ├── credits.txt │ ├── ostrich.jpg │ └── potato.jpg ├── index.html ├── mammal │ └── cat │ └── index.html ├── nginx-modules-reference.pdf ├── ostrich │ └── index.html └── veg └── potato └── index.html
  • 12. ©2022 F5 12 Our config file: server { listen 80 default_server; server_name www.snarketing.net; access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /cat { root /usr/share/nginx/html/mammal; } location /potato { root /usr/share/nginx/html/veg; } … }
  • 13. ©2022 F5 13 Example location /cat { root /usr/share/nginx/html/mammal; } ├── mammal └── cat └── index.html Not Secure | http://www.snarketing.net/cat
  • 14. ©2022 F5 14 What if? location /ostrich { proxy_set_header foo "test"; }
  • 15. ©2022 F5 15 Solution server { listen 80 default_server; server_name www.snarketing.net; access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /cat { root /usr/share/nginx/html/mammal; } location /potato { root /usr/share/nginx/html/veg; } … root /usr/share/nginx/html;
  • 17. ©2022 F5 17 3. Using ‘if’ in a location context
  • 18. ©2022 F5 18 “Directive if has problems when used in location context, in some cases it doesn’t do what you expect but something completely different instead. In some cases it even segfaults. It’s generally a good idea to avoid it if possible.”
  • 19. ©2022 F5 19 • Usually computationally more expensive than an in-built function • Takes a deep understanding of how if executes in the NGINX rewrite module to avoid problems (NGINX 301?) • Can cause an NGINX SIGSEV (bad) Reasons not to use “if” in a location Context
  • 20. ©2022 F5 20 Example: Don’t use if to check for a file server { listen 80 default_server; server_name www.snarketing.net; access_log /var/log/nginx/host.access.log main; index index.html index.htm; root /usr/share/nginx/html; location / { if (!-f $request_filename) { break; } } …
  • 21. ©2022 F5 21 Use try_files instead server { listen 80 default_server; server_name www.snarketing.net; access_log /var/log/nginx/host.access.log main; index index.html index.htm; root /usr/share/nginx/html; location / { try_files $uri $uri/ /index.html; } }
  • 23. ©2022 F5 23 4. Directive Inheritance Confusion
  • 24. ©2022 F5 24 Directives are inherited ”outside in” http { server { location foo { root /home/user/public_html; } } } root /home/user/foo; Sets directive Inherits Directive Overrides directive
  • 25. ©2022 F5 25 Array type directives can have multiple values – the most common example is add_header Beware of array-type Directives location / { add_header My-Header 1; add_header My-Other-Header 2; add_header My-Other-Othe-Header 3; } You might think that inheritance would work by adding the headers together server { … add_header My-Header 1; location / { add_header My-Other-Header 2; } But you would be wrong!
  • 26. ©2022 F5 26 Example: add_header http { add_header X-HTTP-LEVEL-HEADER 1; add_header X-ANOTHER-HTTP-LEVEL-HEADER 1; server { listen 8080; location / { return 200 "OK"; } } server { listen 8081; add_header X-SERVER-LEVEL-HEADER 1; location / { return 200 "OK"; } location /test { add_header X-LOCATION-LEVEL-HEADER 1; return 200 "OK"; } location /correct { add_header X-HTTP-LEVEL-HEADER 1; add_header X-ANOTHER-HTTP-LEVEL-HEADER 1; add_header X-SERVER-LEVEL-HEADER 1; add_header X-LOCATION-LEVEL-HEADER 1; return 200 "OK"; } } Inherits Replaces Replaces To get all headers must duplicate
  • 28. ©2022 F5 28 5. Not Using Keepalives for upstreams
  • 29. ©2022 F5 29 What are keepalives and why should you care? Upstreams Clients Without keepalives NGINX opens a new connection for each HTTP request Ephemeral port exhaustion
  • 30. ©2022 F5 30 What are keepalives and why should you care? Upstreams Clients With keepalives NGINX reuses connections to upstreams
  • 32. ©2022 F5 32 Use the keepalive directive in the upstream{} block Enabling keepalives upstream http_backend { server 127.0.0.1:8080; keepalive 4; } This ensures that the connection uses the correct HTTP version (HTTP 1 does not support keepalives) Add the following directives to the location{} block location / { proxy_http_version 1.1; proxy_set_header "Connection" ""; proxy_pass http://backend; } What number to set the keepalive value to? We recommend at least 4 x the number of servers listed in the upstream{} block.

Notes de l'éditeur

  1. Welcome intro etc Demo setup ubuntu@54.190.3.225 I have added your private key Script files are in ~/webinar http://www.snarketing.net (public DNS)
  2. Explain these are in no particular order, but we’re starting with the only one that means messing about with the main context.
  3. Explain file descriptors
  4. You can see them in /proc for your process
  5. The default limit is 1024 and you can blow through this
  6. Explain how many you need
  7. This is how to set them.
  8. Run the 1.sh script Show the /etc/nginx/nginx.conf not that this is artificiallcy set to create a files descriptor problem (as its hard to do in a demo) Go to www.snarketing.net – show it works Get the audience to go to www.snarketing.net See it break – tail /var/log/nginx/error.log Run 1fixed.sh Show the /etc/nginx/nginx.conf Repeat with the audience, see tit works and no file errors
  9. This one can catch you out, and it’s a little counter intuitive lets take a look
  10. Explain what a root directive and location block are
  11. Here’s a very basic layout, now let’s take a look at our nginx.conf
  12. Exolain the location / points to /usr/share/nginx and tha the other locations point to other document roots Emphasse there are only /, /cat and /potato – and that something for say /ostrich would go to the / location
  13. Walk through this example
  14. But what If I just want to add a header for a particular location. The content is still in the / root, so no need to add that right? Wrong, it will break because there is no root for the location to inherit
  15. The solution is to have a root in the server context – or always declare a root in the location (but repeated lines are meh)
  16. Demo instructions Run 2.sh Show the /etc/nginx/conf.d/default.conf Check out http://www.snarketing.net/ostrich/. http://www.snarketing.net/cat http://www.snarketing.net/potato Run 2broken.sh Show the /etc/nginx/conf.d/default.conf Explain that we have just added a particular header in the ostrich location Check out http://www.snarketing.net/ostrich/ 404 Baby!!! Explain that this is because there is no location block in the main server{} context, and we don’t set one in the location{} block. The fix is to add the doc root to the main server{} context Run 2fixed.sh Show the /etc/nginx/conf.d/default.conf note the documentroot in the server context Check out http://www.snarketing.net/ostrich/ The bird is back!
  17. I debated on putting this in, but if your organization has a whole article called “if is evil” you kind of have to 
  18. From the article itself
  19. Tell them why
  20. Here’s a simple example – don’t do this there are almost always a better way
  21. Like this
  22. Demo instructions Run 3.sh Show /etc/nginx/conf.d/default.conf go to www.snarketing.net.fubar It works but its ugly Run 3fixed.sh Show default.conf Explain try files is better go to www.snarketing.net.fubar
  23. This can be confusing
  24. Explain directive inheritance
  25. Talk about array type of directives – i.e the ones that are additive – root is ony 1 value at time, but add_header can keep adding headers as much as you like – so you should be able to add more in a different context and inherit the upper levels? No!
  26. This builds and is fairly self explanatory – it shows what inherits and what replaces walk through it not that even if you wanted to redefine 1 header of many, you would need to redefine them all.
  27. Demo instructions: Run 4.sh Show /etc/nginx/conf.d/defult.conf in a different terminal = – note that this includes the http{} context which is less usual but what we need for this demo curl -is localhost:8080 note the headers Explain that this is inheriting from the http{} context curl -is localhost:8081 note the headers For the server listening on port 8081, there is an add_header directive in the server{} block but not in its child location / block. The header defined in the server{} block overrides the two headers defined in the http{} context curl -is localhost:8081/test In the child location /test block, there is an add_header directive and it overrides both the header from its parent server{} block and the two headers from the http{} context: curl -is localhost:8081/correct If we want a location{} block to preserve the headers defined in its parent contexts along with any headers defined locally, we must redefine the parent headers within the location{} block. That’s what we’ve done in the location /correct block:
  28. OK, here’s a performance and scalability one, and it’s easy to implement.
  29. Without keepalives nginx will make a new connecton to an upstream server for every request This may well lead to port exhaustion – because we need an ephemeral port for every connection, and we can run out. plus it’s an overhead to do a TCP handshake for every single http request This problem was solved by keepalives over a decade ago (HTTP1-1.1) Keepalives reuse the same connection for multiple requests and are standard at the front end, but need a coo
  30. Keepalives reuse the same connection for multiple requests and are standard at the front end, but need a couple of settings to enable for the upstream servers – but first let's take a look at what happens without them
  31. Demo instructions: Run 5.sh Show /etc/nginx/conf.d/default.conf Run connections.sh View output – lots of connections to the backend – and this is a small scale test Return to presentation talk long enough for the connections in TIME_WAIT to go away 
  32. Enabling keepalives is easy! Add the keepalive directive to the
  33. Demo Instructions Run 5fixed.sh Show /etc/nginx/conf.d/default.conf Run connections.sh View output – fewer connections to the backend Return to presentation