SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Best Practices for Getting
Started with NGINX Open
Source
Alessandro Fael Garcia
Senior Solutions Engineer – Community & Alliances
©2022 F5
2 Source: https://news.netcraft.com/archives/2022/06/30/june-2022-web-server-survey.html
©2022 F5
3
©2022 F5
4
Installing NGINX
Best practices
©2022 F5
5
Use the NGINX Open Source official repository!
https://nginx.org/en/linux_packages.html
©2022 F5
6
TIL
‱ nginx –t → Check if NGINX configuration is valid
‱ nginx –T → Dump full NGINX configuration
‱ nginx –v → Print NGINX version
‱ nginx –V → Print NGINX package config arguments
‱ nginx –s <start/stop/reload> → Start NGINX; stop (kill) NGINX; reload NGINX configuration (gracefully)
Key NGINX Commands
©2022 F5
7
/etc/nginx/nginx.conf
‱ Main NGINX configuration file
‱ Global settings
‱ Contains sensible defaults (when installing NGINX from our
official repositories)
‱ Avoid modifying unless you know what you are doing
(defaults will work out of the box for >80% of use cases)
‱ Includes HTTP block (adding a Stream block is one of the
few cases where you’d want to modify the file)
/etc/nginx/conf.d/*.conf
‱ Default directory for additional NGINX configuration files
‱ By default, files here are contained within the HTTP context
‱ default.conf includes sample configuration with the NGINX
default landing page
‱ Start with a single configuration file, split your configuration
into further files as necessary
Recommended NGINX Directory Structure
Defaults? What defaults?!
©2022 F5
8
Use Let’s Encrypt and Certbot for easy certs!
https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal
©2022 F5
9
Tuning NGINX
One step at a time
©2022 F5
10
nginx.conf
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
proxy_cache_lock on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
...
}
}
}
©2022 F5
11
worker_processes
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
Make sure you spawn one NGINX worker process per CPU
core (default: 1)
©2022 F5
12
worker_connections & worker_rlimit_nofile
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
a) Increase the worker connections to >1024 (default: 512)
b) Increase the limit on the maximum number of open files
to at least twice the number of worker connections
(default: system limit)
©2022 F5
13
access_log
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
‱ Turn off the access log for extra performance (default: on)
or
‱ Set a buffer or a time to only write logs at an interval
(default: off)
©2022 F5
14
keepalive
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
Use keepalives to keep connections to upstream servers
open (default: 0) → You will need to set HTTP to 1.1 and
rewrite the Connection header
©2022 F5
15
ssl_session_cache
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
Cache and share your SSL sessions between all your NGINX
processes (default: disabled)
©2022 F5
16
proxy_cache_lock
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
Send only one request to the upstream server when there
are multiple cache misses for the same file (default: off)
©2022 F5
17
Recap
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
worker_processes auto;
worker_rlimit_nofile 2048;
...
events {
worker_connections 1024;
}
http {
access_log off;
sendfile on;
tcp_nopush on;
...
upstream app {
server w.x.y.z;
keepalive 2;
...
}
server {
access_log /var/log/nginx/access.log main buffer=512k
flush=5m;
ssl_session_cache shared:SSL:10m;
...
location / {
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_pass http://app;
proxy_cache_lock on;
...
}
}
}
‱ Make sure you spawn one NGINX worker process per
CPU core (default: 1)
‱ Increase the worker connections to >1024 (default: 512)
‱ Increase the limit on the maximum number of open files to
at least twice the number of worker connections (default:
system limit)
‱ Turn off the access log for extra performance (default: on)
‱ Set a buffer or a time to only write logs at an interval
(default: off)
‱ Use keepalives to keep connections to upstream servers
open (default: 0) → You will need to set HTTP to 1.1 and
rewrite the Connection header
‱ Cache and share your SSL sessions between all your
NGINX processes (default: disabled)
‱ Send only one request to the upstream server when there
are multiple cache misses for the same file (default: off)
©2022 F5
18
Common NGINX Mistakes
That we’ve all made at some stage
©2022 F5
19
error_log
nginx.conf
1
2
3
...
error_log off;
...
nginx.conf
1
2
3
...
error_log /dev/null emerg;
...
Creates an error log named off
Redirects error log data to /dev/null
©2022 F5
20
Directive inheritance is not additive
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
http {
add_header HTTP_HEADER;
...
server {
add_header HTTP_HEADER;
...
location / {
add_header HTTP_HEADER;
add_header LOCATION_HEADER:
...
}
}
}
Sets directive
Inherits directive
Overrides directive
©2022 F5
21
ip_hash
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
http {
...
upstream {
ip_hash;
server 10.10.20.105:8080;
server 10.10.20.106:8080;
server 10.10.20.108:8080;
}
server {
...
}
}
If all your traffic comes from the same CIDR block,
use hash or any other load balancing algorithm instead
©2022 F5
22
proxy_buffering
nginx.conf
1
2
3
4
http {
proxy_buffering off;
...
}
Avoiding buffers might speed up the initial response to your client,
but it might also saturate your open connections
©2022 F5
23
stub_status
nginx.conf
1
2
3
4
5
6
server {
...
location = /status {
stub_status;
}
}
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
server {
...
location = /status {
satisfy any;
auth_basic “closed site”;
auth_basic_user_file conf.d/.htpasswd;
allow 192.168.1.0/24;
deny all;
stub_status;
}
}
Everyone can access your data
Secure access to your data
©2022 F5
24
proxy_pass
nginx.conf
1
2
3
4
5
6
7
8
9
10
http {
...
server {
...
location / {
...
proxy_pass http://localhost:3000/;
}
}
}
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
http {
...
upstream node_backend {
zone upstreams 64K;
hash;
server 127.0.0.1:3000 max_fails=1 fail_timeout=2s;
server 127.0.0.1:5000 max_fails=1 fail_timeout=2s;
keepalive 4;
}
server {
...
location / {
...
proxy_next_upstream error timeout http_500;
proxy_pass http://node_backend/;
}
}
}
Proxy to an upstream server directly
‱ Load balance
‱ Upstream stats
‱ Keepalives
‱ Passive health checks
‱ Define behavior if the upstream servers go down
©2022 F5
25
If is Evil
Much Computationally Expensive!
Very Segfaults đŸ˜±
If only works as intended if you use return or rewrite inside your if block
©2022 F5
26
‱ error_log off != turn off the error log
‱ Directive inheritance is not additive
‱ ip_hash does not work for addresses under the same CIDR block
‱ proxy_buffering off might lead unexpected saturated connections
‱ Beware of not properly securing your stat locations
‱ It’s better to proxy_pass to upstream groups than directly to an upstream server
‱ If. Is. Evil.
Recap
©2022 F5
27
Thankyouforattending!
a.faelgarcia@f5.com
alessfg
@alessfg
Alessandro Fael Garcia
©2022 F5
29
Further Resources
‱ Performance-Tuning NGINX https://www.youtube.com/watch?v=YEdhuC2muOE
‱ Best Practices for NGINX https://www.youtube.com/watch?v=pkHQCPXaimU
‱ Avoiding the Top 10 NGINX Configuration Mistakes https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes
‱ Tuning NGINX for Performance https://www.nginx.com/blog/tuning-nginx/

Weitere Àhnliche Inhalte

Was ist angesagt?

WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
Brian Grant
 

Was ist angesagt? (20)

Open shift 4 infra deep dive
Open shift 4    infra deep diveOpen shift 4    infra deep dive
Open shift 4 infra deep dive
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Intro to Helm for Kubernetes
Intro to Helm for KubernetesIntro to Helm for Kubernetes
Intro to Helm for Kubernetes
 
OpenStack API's and WSGI
OpenStack API's and WSGIOpenStack API's and WSGI
OpenStack API's and WSGI
 
Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...
Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...
Practical CephFS with nfs today using OpenStack Manila - Ceph Day Berlin - 12...
 
Red Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform OverviewRed Hat OpenShift Container Platform Overview
Red Hat OpenShift Container Platform Overview
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training Session
 
[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS ì–Žë””êčŒì§€ 왔니? - Octavia 소개
[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS ì–Žë””êčŒì§€ 왔니? - Octavia 소개[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS ì–Žë””êčŒì§€ 왔니? - Octavia 소개
[OpenInfra Days Korea 2018] (Track 2) Neutron LBaaS ì–Žë””êčŒì§€ 왔니? - Octavia 소개
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
 
Room 1 - 7 - LĂȘ Quốc ĐáșĄt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - LĂȘ Quốc ĐáșĄt - Upgrading network of Openstack to SDN with Tungste...Room 1 - 7 - LĂȘ Quốc ĐáșĄt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - LĂȘ Quốc ĐáșĄt - Upgrading network of Openstack to SDN with Tungste...
 
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
 
NGINX 101: Web Traffic Encryption with SSL/TLS and NGINX
NGINX 101: Web Traffic Encryption with SSL/TLS and NGINXNGINX 101: Web Traffic Encryption with SSL/TLS and NGINX
NGINX 101: Web Traffic Encryption with SSL/TLS and NGINX
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINX
 
GitOps with Gitkube
GitOps with GitkubeGitOps with Gitkube
GitOps with Gitkube
 
Gitops: the kubernetes way
Gitops: the kubernetes wayGitops: the kubernetes way
Gitops: the kubernetes way
 
[였픈소슀컚섀팅] Open Stack Ceph, Neutron, HA, Multi-Region
[였픈소슀컚섀팅] Open Stack Ceph, Neutron, HA, Multi-Region[였픈소슀컚섀팅] Open Stack Ceph, Neutron, HA, Multi-Region
[였픈소슀컚섀팅] Open Stack Ceph, Neutron, HA, Multi-Region
 
5 things you didn't know nginx could do
5 things you didn't know nginx could do5 things you didn't know nginx could do
5 things you didn't know nginx could do
 
Tutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting routerTutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting router
 

Ähnlich wie Best Practices for Getting Started with NGINX Open Source

How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptxHow to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
NGINX, Inc.
 

Ähnlich wie Best Practices for Getting Started with NGINX Open Source (20)

How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptxHow to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
 
Warden @ Meet magento Romania 2021
Warden @ Meet magento Romania 2021Warden @ Meet magento Romania 2021
Warden @ Meet magento Romania 2021
 
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
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
 
Open Sourcing NGINX Agent and Demo
Open Sourcing NGINX Agent and DemoOpen Sourcing NGINX Agent and Demo
Open Sourcing NGINX Agent and Demo
 
FaSilETÂČ full end-to-end testing solution presented at OW2con'19, June 12-13,...
FaSilETÂČ full end-to-end testing solution presented at OW2con'19, June 12-13,...FaSilETÂČ full end-to-end testing solution presented at OW2con'19, June 12-13,...
FaSilETÂČ full end-to-end testing solution presented at OW2con'19, June 12-13,...
 
NGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App ServerNGINX Unit: Rebooting our Universal Web App Server
NGINX Unit: Rebooting our Universal Web App Server
 
NGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best PracticesNGINX ADC: Basics and Best Practices
NGINX ADC: Basics and Best Practices
 
Sprint 17
Sprint 17Sprint 17
Sprint 17
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetes
 
OSMC 2021 | Icinga-Installer – the easy way to your Icinga
OSMC 2021 | Icinga-Installer – the easy way to your IcingaOSMC 2021 | Icinga-Installer – the easy way to your Icinga
OSMC 2021 | Icinga-Installer – the easy way to your Icinga
 
Présentation "Docker + Kubernetes" @ Pastis.tech #2
Présentation "Docker + Kubernetes" @ Pastis.tech #2Présentation "Docker + Kubernetes" @ Pastis.tech #2
Présentation "Docker + Kubernetes" @ Pastis.tech #2
 
NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)
 
How to install nginx vs unicorn
How to install nginx vs unicornHow to install nginx vs unicorn
How to install nginx vs unicorn
 
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
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
3-sdn-lab.pdf
3-sdn-lab.pdf3-sdn-lab.pdf
3-sdn-lab.pdf
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ Extension
 
nix-processmgmt: An experimental Nix-based process manager-agnostic framework
nix-processmgmt: An experimental Nix-based process manager-agnostic frameworknix-processmgmt: An experimental Nix-based process manager-agnostic framework
nix-processmgmt: An experimental Nix-based process manager-agnostic framework
 

Mehr von NGINX, Inc.

Kubernetesç’°ćąƒă§ćźŸçŸă™ă‚‹WebケプăƒȘă‚±ăƒŒă‚·ăƒ§ăƒłă‚»ă‚­ăƒ„ăƒȘティ
Kubernetesç’°ćąƒă§ćźŸçŸă™ă‚‹WebケプăƒȘă‚±ăƒŒă‚·ăƒ§ăƒłă‚»ă‚­ăƒ„ăƒȘティKubernetesç’°ćąƒă§ćźŸçŸă™ă‚‹WebケプăƒȘă‚±ăƒŒă‚·ăƒ§ăƒłă‚»ă‚­ăƒ„ăƒȘティ
Kubernetesç’°ćąƒă§ćźŸçŸă™ă‚‹WebケプăƒȘă‚±ăƒŒă‚·ăƒ§ăƒłă‚»ă‚­ăƒ„ăƒȘティ
NGINX, Inc.
 

Mehr von 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ケプăƒȘă‚±ăƒŒă‚·ăƒ§ăƒłă‚»ă‚­ăƒ„ăƒȘティ
 

KĂŒrzlich hochgeladen

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Bert Jan Schrijver
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

KĂŒrzlich hochgeladen (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

Best Practices for Getting Started with NGINX Open Source

  • 1. Best Practices for Getting Started with NGINX Open Source Alessandro Fael Garcia Senior Solutions Engineer – Community & Alliances
  • 2. ©2022 F5 2 Source: https://news.netcraft.com/archives/2022/06/30/june-2022-web-server-survey.html
  • 5. ©2022 F5 5 Use the NGINX Open Source official repository! https://nginx.org/en/linux_packages.html
  • 6. ©2022 F5 6 TIL ‱ nginx –t → Check if NGINX configuration is valid ‱ nginx –T → Dump full NGINX configuration ‱ nginx –v → Print NGINX version ‱ nginx –V → Print NGINX package config arguments ‱ nginx –s <start/stop/reload> → Start NGINX; stop (kill) NGINX; reload NGINX configuration (gracefully) Key NGINX Commands
  • 7. ©2022 F5 7 /etc/nginx/nginx.conf ‱ Main NGINX configuration file ‱ Global settings ‱ Contains sensible defaults (when installing NGINX from our official repositories) ‱ Avoid modifying unless you know what you are doing (defaults will work out of the box for >80% of use cases) ‱ Includes HTTP block (adding a Stream block is one of the few cases where you’d want to modify the file) /etc/nginx/conf.d/*.conf ‱ Default directory for additional NGINX configuration files ‱ By default, files here are contained within the HTTP context ‱ default.conf includes sample configuration with the NGINX default landing page ‱ Start with a single configuration file, split your configuration into further files as necessary Recommended NGINX Directory Structure Defaults? What defaults?!
  • 8. ©2022 F5 8 Use Let’s Encrypt and Certbot for easy certs! https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal
  • 10. ©2022 F5 10 nginx.conf nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; proxy_cache_lock on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; ... } } }
  • 11. ©2022 F5 11 worker_processes nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } Make sure you spawn one NGINX worker process per CPU core (default: 1)
  • 12. ©2022 F5 12 worker_connections & worker_rlimit_nofile nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } a) Increase the worker connections to >1024 (default: 512) b) Increase the limit on the maximum number of open files to at least twice the number of worker connections (default: system limit)
  • 13. ©2022 F5 13 access_log nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } ‱ Turn off the access log for extra performance (default: on) or ‱ Set a buffer or a time to only write logs at an interval (default: off)
  • 14. ©2022 F5 14 keepalive nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } Use keepalives to keep connections to upstream servers open (default: 0) → You will need to set HTTP to 1.1 and rewrite the Connection header
  • 15. ©2022 F5 15 ssl_session_cache nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } Cache and share your SSL sessions between all your NGINX processes (default: disabled)
  • 16. ©2022 F5 16 proxy_cache_lock nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } Send only one request to the upstream server when there are multiple cache misses for the same file (default: off)
  • 17. ©2022 F5 17 Recap nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ... worker_processes auto; worker_rlimit_nofile 2048; ... events { worker_connections 1024; } http { access_log off; sendfile on; tcp_nopush on; ... upstream app { server w.x.y.z; keepalive 2; ... } server { access_log /var/log/nginx/access.log main buffer=512k flush=5m; ssl_session_cache shared:SSL:10m; ... location / { proxy_http_version 1.1; proxy_set_header Connection “”; proxy_pass http://app; proxy_cache_lock on; ... } } } ‱ Make sure you spawn one NGINX worker process per CPU core (default: 1) ‱ Increase the worker connections to >1024 (default: 512) ‱ Increase the limit on the maximum number of open files to at least twice the number of worker connections (default: system limit) ‱ Turn off the access log for extra performance (default: on) ‱ Set a buffer or a time to only write logs at an interval (default: off) ‱ Use keepalives to keep connections to upstream servers open (default: 0) → You will need to set HTTP to 1.1 and rewrite the Connection header ‱ Cache and share your SSL sessions between all your NGINX processes (default: disabled) ‱ Send only one request to the upstream server when there are multiple cache misses for the same file (default: off)
  • 18. ©2022 F5 18 Common NGINX Mistakes That we’ve all made at some stage
  • 19. ©2022 F5 19 error_log nginx.conf 1 2 3 ... error_log off; ... nginx.conf 1 2 3 ... error_log /dev/null emerg; ... Creates an error log named off Redirects error log data to /dev/null
  • 20. ©2022 F5 20 Directive inheritance is not additive nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 http { add_header HTTP_HEADER; ... server { add_header HTTP_HEADER; ... location / { add_header HTTP_HEADER; add_header LOCATION_HEADER: ... } } } Sets directive Inherits directive Overrides directive
  • 21. ©2022 F5 21 ip_hash nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 http { ... upstream { ip_hash; server 10.10.20.105:8080; server 10.10.20.106:8080; server 10.10.20.108:8080; } server { ... } } If all your traffic comes from the same CIDR block, use hash or any other load balancing algorithm instead
  • 22. ©2022 F5 22 proxy_buffering nginx.conf 1 2 3 4 http { proxy_buffering off; ... } Avoiding buffers might speed up the initial response to your client, but it might also saturate your open connections
  • 23. ©2022 F5 23 stub_status nginx.conf 1 2 3 4 5 6 server { ... location = /status { stub_status; } } nginx.conf 1 2 3 4 5 6 7 8 9 10 11 server { ... location = /status { satisfy any; auth_basic “closed site”; auth_basic_user_file conf.d/.htpasswd; allow 192.168.1.0/24; deny all; stub_status; } } Everyone can access your data Secure access to your data
  • 24. ©2022 F5 24 proxy_pass nginx.conf 1 2 3 4 5 6 7 8 9 10 http { ... server { ... location / { ... proxy_pass http://localhost:3000/; } } } nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 http { ... upstream node_backend { zone upstreams 64K; hash; server 127.0.0.1:3000 max_fails=1 fail_timeout=2s; server 127.0.0.1:5000 max_fails=1 fail_timeout=2s; keepalive 4; } server { ... location / { ... proxy_next_upstream error timeout http_500; proxy_pass http://node_backend/; } } } Proxy to an upstream server directly ‱ Load balance ‱ Upstream stats ‱ Keepalives ‱ Passive health checks ‱ Define behavior if the upstream servers go down
  • 25. ©2022 F5 25 If is Evil Much Computationally Expensive! Very Segfaults đŸ˜± If only works as intended if you use return or rewrite inside your if block
  • 26. ©2022 F5 26 ‱ error_log off != turn off the error log ‱ Directive inheritance is not additive ‱ ip_hash does not work for addresses under the same CIDR block ‱ proxy_buffering off might lead unexpected saturated connections ‱ Beware of not properly securing your stat locations ‱ It’s better to proxy_pass to upstream groups than directly to an upstream server ‱ If. Is. Evil. Recap
  • 28.
  • 29. ©2022 F5 29 Further Resources ‱ Performance-Tuning NGINX https://www.youtube.com/watch?v=YEdhuC2muOE ‱ Best Practices for NGINX https://www.youtube.com/watch?v=pkHQCPXaimU ‱ Avoiding the Top 10 NGINX Configuration Mistakes https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes ‱ Tuning NGINX for Performance https://www.nginx.com/blog/tuning-nginx/