title: Nginx local proxy with backup to prod server
body: <p>I am trying to setup nginx proxy on my local machine.
  What I want to achieve is like this:</p>
  <p>site.local -&gt; proxy_pass -&gt; HTTP://localhost:3000
  if localhost:3000 is down, then proxy to -&gt; site.com</p>
  <p>So far this is my config:</p>
  <pre><code>upstream mysite {
    server localhost:3000 fail_timeout = 5 max_fails = 1;
    server example.com backup max_fails = 2;
  }
  
  server {
    server_name site.local;
    listen ssl;
    ssl_certificate /path/to/site-local.crt;
    ssl_certificate_key /path/to/site-local.key;
    ssl_ciphers HIGH: !aNULL: !MD5;
  
  
    location / {
      proxy_pass https://mysite;
      proxy_set_header Host site.com;
      proxy_set_header X-Forwarded-For $remote_addr;
    }
  }
  </code></pre>
  <p>And I've made entry in <code>hosts</code> file for <code>site.local 127.0.0.1</code>.</p>
  <p>I am getting multiple errors with slightly different configurations:</p>
  <ol>
  <li>I am doing <code>proxy_pass HTTP://mysite</code>, then it is 301 redirecting to <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>, and not proxying to https.</li>
  <li>If I did <code>proxy_pass: https://mysite</code>, then it is giving 502.</li>
  <li>If I am doing <code>server site.com:443</code> then it is saying non https traffic to 443 server is not allowed.</li>
  </ol>
  <p>Any ideas around how to achieve this.</p>