title: NGINX Proxy pass to external site that has internal redirect
body: <p>i'm trying to configure an nginx proxy that hide an internal site via the proxy pass but without success.
  the config i used is</p>
  <pre><code>location /internal1/ {
     proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_connect_timeout 15;
     proxy_read_timeout 180;
     proxy_pass http://internal1/;
  }
  
  upstream internal1 {
     server a.b.c.d:80;
  }
  </code></pre>
  <p>the problem is that when i try to reach the a.b.c.d site it redirect to a login page that sould be <a href="http://a.b.c.d/login" rel="nofollow noreferrer">http://a.b.c.d/login</a> and after i login it redirect at another page <a href="http://a.b.c.d/device/config" rel="nofollow noreferrer">http://a.b.c.d/device/config</a> . with the proxy it redirect to http://mysite/login and http://mysite/device/config</p>
  <p>that make the proxy do not work and show me resource not found and i couldn not see any of the pages.</p>
  <p>If i change the proxy_pass value to <a href="http://a.b.c.d/login/" rel="nofollow noreferrer">http://a.b.c.d/login/</a> it show the login page at http://mysite/internal1 and after i login it show no resource found because it try to reach http://mysite/device/config.</p>
  <p>someone have some suggestion on how to configure it in the proper way?</p>
  <p>thanks for all the answer</p>
  <p>EDIT:
  sorry for the late answer but i got very busy in the meanwhile, anyway that solution work for 1 device but now all my device connected go only that device &quot;internal&quot; page and i cannot differentiate between more cause nginx do not support the same location in multiple config ( all device have ip/page1 )</p>
  <pre><code>location /page1/
  { 
   proxy_pass mysite/internal1/page1;
   proxy_redirect off;
   proxy_set_header Host $host;
  }
  </code></pre>
  <p>EDIT2:
  unlucky it's not possible to expose all device to internet directly. the solution i found is:</p>
  <p>create a custom DNS subdomain and then create a different nginx server block for every device with his own location and future redirect/proxy ecc...</p>