How to Avoid the Top 5 NGINX Configuration Mistakes.pptx

NGINX, Inc.
8 Sep 2022
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
How to Avoid the Top 5 NGINX Configuration Mistakes.pptx
1 sur 35

Contenu connexe

Similaire à How to Avoid the Top 5 NGINX Configuration Mistakes.pptx

NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Dockersarahnovotny
NGiNX, VHOSTS & SSL (let's encrypt)NGiNX, VHOSTS & SSL (let's encrypt)
NGiNX, VHOSTS & SSL (let's encrypt)Marcel Cattaneo
Managing and Monitoring Application PerformanceManaging and Monitoring Application Performance
Managing and Monitoring Application PerformanceSebastian Marek
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 OverviewLeo Lorieri
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak

Plus de NGINX, Inc.

【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法
【NGINXセミナー】 Ingressを使ってマイクロサービスの運用を楽にする方法NGINX, Inc.
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナーNGINX, Inc.
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法NGINX, Inc.
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 & KubecostManaging Kubernetes Cost and Performance with NGINX & Kubecost
Managing Kubernetes Cost and Performance with NGINX & KubecostNGINX, Inc.
Manage Microservices Chaos and Complexity with ObservabilityManage Microservices Chaos and Complexity with Observability
Manage Microservices Chaos and Complexity with ObservabilityNGINX, Inc.

Plus de NGINX, Inc.(20)

Dernier

Semantic Search_ NLP_ ML.pdfSemantic Search_ NLP_ ML.pdf
Semantic Search_ NLP_ ML.pdfPlamenaDzharadat
Jens Happe - Write tests you love, not hate.pdfJens Happe - Write tests you love, not hate.pdf
Jens Happe - Write tests you love, not hate.pdfJens Happe
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
Alliance Expedition BattleAlliance Expedition Battle
Alliance Expedition BattleSilver Caprice
BioSmalltalkBioSmalltalk
BioSmalltalkESUG
La strada verso il successo con i database a grafo, la Graph Data Science e l...La strada verso il successo con i database a grafo, la Graph Data Science e l...
La strada verso il successo con i database a grafo, la Graph Data Science e l...Neo4j

How to Avoid the Top 5 NGINX Configuration Mistakes.pptx

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