title: Using a variable for proxy_pass to prevent nginx from crashing if host in upstream is not found
body: <p>I tried to prevent nginx from crashing when the upstream is not found by using a variable for the proxy_pass (as explained in <a href="https://stackoverflow.com/questions/32845674/setup-nginx-not-to-crash-if-host-in-upstream-is-not-found">this stackoverflow thread</a>):</p>
  <pre><code># Set front-dev in a variable to let nginx start even if it is not accessible (which is the case in production)
  set $frontdev front-dev;
  resolver 127.0.0.11 [::1]; # in a docker environment
  
  location /dev/ {
      proxy_pass              http://$frontdev:4200/;
  
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection &quot;Upgrade&quot;;
  }
  
  </code></pre>
  <p>That way nginx starts without crashing, but an empty html page is returned instead of the resources when I connect to the upstream.</p>
  <p>Firefox returns this error:</p>
  <pre><code>Uncaught SyntaxError: expected expression, got '&lt;'    jquery.min.js:1
  </code></pre>
  <p>Since this file is returned instead of <code>jquery.min.js</code>:</p>
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  
  &lt;head&gt;
      &lt;title&gt;Shanoir&lt;/title&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;link rel=&quot;shortcut icon&quot; href=&quot;assets/images/favicon.ico&quot; type=&quot;image/x-icon&quot;&gt;
      &lt;link href=&quot;assets/css/awesome.min.css&quot; rel=&quot;stylesheet&quot;&gt;
      &lt;script src=&quot;/auth/js/keycloak.js&quot;&gt;&lt;/script&gt;
      &lt;script defer type=&quot;text/javascript&quot; src=&quot;assets/papaya-nojquery/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script defer type=&quot;text/javascript&quot; src=&quot;assets/papaya-nojquery/papaya.js&quot;&gt;&lt;/script&gt;
      &lt;script defer type=&quot;text/javascript&quot; src=&quot;assets/jszip.min.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
    &lt;app-root&gt;&lt;/app-root&gt;
  &lt;script src=&quot;runtime.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;&lt;script src=&quot;polyfills.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;&lt;script src=&quot;styles.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;&lt;script src=&quot;vendor.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;&lt;script src=&quot;main.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Here are some nginx logs:</p>
  <pre><code>shanoir-ng-nginx            | 172.18.0.1 - - [16/Nov/2020:15:55:09 +0000] &quot;GET /dev/ HTTP/1.1&quot; 200 408 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0&quot; &quot;-&quot;
  shanoir-ng-nginx            | 172.18.0.1 - - [16/Nov/2020:15:55:09 +0000] &quot;GET /dev/assets/css/awesome.min.css HTTP/1.1&quot; 200 408 &quot;https://shanoir-ng-nginx/dev/&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0&quot; &quot;-&quot;
  shanoir-ng-nginx            | 172.18.0.1 - - [16/Nov/2020:15:55:09 +0000] &quot;GET /dev/polyfills.js HTTP/1.1&quot; 200 408 &quot;https://shanoir-ng-nginx/dev/&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0&quot; &quot;-&quot;
  [...]
  </code></pre>
  <p><strong>Note</strong></p>
  <p>This config works perfectly, but the upstream must be up before nginx starts:</p>
  <pre><code>
  # Front development with angular-cli server
  location /dev/ {
      proxy_pass              http://front-dev:4200/;
  
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection &quot;Upgrade&quot;;
  }
  
  </code></pre>
  <p>I don't understand what is missing, any idea?</p>