Avoiding the top Nginx configuration mistakes
What upsets me about Nginx the most is that it takes the fail-fast approach, which isn&#x27;t entirely suitable for combining it with a container workflow, at least in situations where you&#x27;re running it without something like Kubernetes (which has its own customizations).<p>For example, currently i run my own Nginx ingress with Docker Swarm:<p><pre><code>  service A &#x2F; B &#x2F; C &lt;--&gt; Nginx &lt;--&gt; browser
</code></pre>
The reverse proxy configuration feels easier to do than that of Apache2&#x2F;httpd, for example:<p><pre><code>    server {
      listen 80;
      server_name app.test.my-company.com;
      return 301 https:&#x2F;&#x2F;$host$request_uri;
  }
  server {
      listen 443 ssl http2;
      server_name app.test.my-company.com;

      # Configuration for SSL&#x2F;TLS certificates
      ssl_certificate &#x2F;app&#x2F;certs&#x2F;test.my-company.com.crt;
      ssl_certificate_key &#x2F;app&#x2F;certs&#x2F;test.my-company.com.key;

      # Proxy headers
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
   
      # Reverse proxy
      location &#x2F; {
          resolver 127.0.0.11 valid=30s; # Docker DNS
          proxy_pass http:&#x2F;&#x2F;my-app:8080&#x2F;;
          proxy_redirect default;
      }

  }
</code></pre>
However, suppose that the &quot;my-app&quot; container has a health check set up for it. What does that mean? Docker Swarm won&#x27;t route any traffic to it until it&#x27;s finished initialization. Except that it also means that DNS requests won&#x27;t return anything for &quot;my-app&quot; until at least one healthcheck passes. That in of itself shouldn&#x27;t be too problematic, right? Any web server surely would just log that one request as an error and return an error until eventually everything would work.<p>Wrong. Nginx does throw the error and the request fails, but the ENTIRE web server goes down:<p><pre><code>  nginx: [emerg] host not found in upstream &quot;my-app&quot;
</code></pre>
What does that mean? If you have 1 Nginx instance on the server that needs to proxy 10 apps in total, one app not being available will prevent the other 9 from working! Whoever thought that such defaults would be okay has reasoning that is beyond me, especially considering that the Caddy web server does something similar and will go down if 1 out of 10 sites fails to provision the SSL&#x2F;TLS certificate, instead of letting the others work - completely opposite of what someone who cares about resiliency would want!<p>But fear not, supposedly there&#x27;s a solution!<p><pre><code>  # Reverse proxy
  location &#x2F; {
      resolver 127.0.0.11 valid=30s; # Docker DNS
      set $proxy_server my-app;
      proxy_pass http:&#x2F;&#x2F;$proxy_server:8080&#x2F;;
      proxy_redirect default;
  }
</code></pre>
Except that, you know, that also doesn&#x27;t work:<p><pre><code>  nginx: [emerg] &quot;proxy_redirect default&quot; cannot be used with &quot;proxy_pass&quot; directive with variables
</code></pre>
Now, that&#x27;s not an issue in my case, since i just jotted down the &quot;proxy_redirect default;&quot; value to remember what it does, but it&#x27;s unfortunate to hear that it is neither ignored (since it&#x27;s the default value which is functionally identical to it not being there), nor could other values be used: <a href="http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_proxy_module.html#proxy_redirect" rel="nofollow">http:&#x2F;&#x2F;nginx.org&#x2F;en&#x2F;docs&#x2F;http&#x2F;ngx_http_proxy_module.html#pro...</a><p>In summary, it&#x27;s nice that there are workaround for problems like that, but it&#x27;s a bit odd that the web server is otherwise so quick to fall over and die, as well as the fact that the defaults aren&#x27;t oriented towards maximum reliability and resilience. That said, i still do like Nginx and actually wrote about how to use it as a reverse proxy on my blog a while back: <a href="https:&#x2F;&#x2F;blog.kronis.dev&#x2F;tutorials&#x2F;how-to-use-nginx-to-proxy-your-front-end-and-back-end" rel="nofollow">https:&#x2F;&#x2F;blog.kronis.dev&#x2F;tutorials&#x2F;how-to-use-nginx-to-proxy-...</a><p>But at the same time, in situations where load isn&#x27;t high enough for the web server to be the bottleneck, it&#x27;s also helpful to evaluate the alternatives, notably: Apache2&#x2F;httpd, Caddy and Traefik. It was actually pretty recently that Apache2&#x2F;httpd got mod_md, which allows provisioning Let&#x27;s Encrypt certificates out of the box, which is certainly promising: <a href="https:&#x2F;&#x2F;httpd.apache.org&#x2F;docs&#x2F;trunk&#x2F;mod&#x2F;mod_md.html" rel="nofollow">https:&#x2F;&#x2F;httpd.apache.org&#x2F;docs&#x2F;trunk&#x2F;mod&#x2F;mod_md.html</a>