title: Can we set up Nginx upstream with different paths?
body: <p>Im setting up docker dev environment that can run several app servers in one container. I also have real servers running in our test environment. Lets say I have 10 servers in the container but I dont want all to run at the same time. I want to set up nginx to route traffic for each app based on if the local server is running (sort of like a circuit breaker pattern). The below config is almost what I want but the issue is I need it to map to a different path if it uses the 'backup' server. I should also mention I have a /etc/host file config to hijack the requests to test.mycompany.com and route them to local nginx 127.0.0.1.</p>
  <pre><code>upstream myapp{
    server 127.0.0.1:8082;
    server 172.26.1.1:80 backup;
  }
  
  server {
    listen 80;
  
    location /approot/ {
      proxy_pass http://myapp/;
    }
  }
  </code></pre>
  <p>As an example take this URL which runs from inside the docker host. host file config ensures it routes through nginx in the container:</p>
  <ul>
  <li><a href="http://test.mycompany.com:80/approot/home" rel="nofollow noreferrer">http://test.mycompany.com:80/approot/home</a></li>
  </ul>
  <p>If the server is up and running in the docker container nginx should route the request to:</p>
  <ul>
  <li><a href="http://127.0.0.1/home" rel="nofollow noreferrer">http://127.0.0.1/home</a></li>
  </ul>
  <p>If the server is down it should go to the backup server but with different path:</p>
  <ul>
  <li><a href="http://172.26.1.1:80/approot/home" rel="nofollow noreferrer">http://172.26.1.1:80/approot/home</a></li>
  </ul>
  <p>its basically working except I cant figure out how to add /approot/ back in for the backup server.</p>