title: Server behind nginx reverse proxy ignores relative path in URL
body: <p>My title isn't the best, my knowledge of webstuff is quite basic, sorry.</p>
  
  <h1>What I want to achieve</h1>
  
  <p>I have one box <strong>fanbox</strong> running nginx on Archlinux that I use as main entry point to my home LAN from the internet (namely work where I can only get out to port 80 and 443) via the reverse proxy facility using a changing domain name over which I have no control and that we will call <strong>home.net</strong> for now.</p>
  
  <p><strong>fanbox</strong> has its ports 80 and 443 mapped to <strong>home.net</strong>, that part was easy.</p>
  
  <p>I have 2 webservers behind the firewall, <strong>web1.lan</strong>, <strong>web2.lan</strong>, <strong>web2ilo.lan</strong>. Both of these have various applications (which may have same name on different machines) that can directly be accessed on the LAN via standard URLs (the names are given as examples, I have no control over the content):</p>
  
  <pre><code>http://web1.lan/phpAdmin/
  http://web1.lan/gallery/
  http://web2.lan/phpAdmin/
  http://web2.lan/dlna/
  </code></pre>
  
  <p>...and so on...</p>
  
  <p>Now <strong>web2ilo.lan</strong> is a particular case. It's the out of band management web interface of the HP server <strong>web2.lan</strong>. That particular webserver offers only 1 application, so it can only be accessed via its root URL:</p>
  
  <pre><code>http://web2ilo/login.html 
  </code></pre>
  
  <p>My goal is to access these via subpath of <strong>home.net</strong> like this:</p>
  
  <pre><code>http://home.net/web1/phpAdmin/
  http://home.net/web1/gallery/
  http://home.net/web2/phpAdmin/
  http://home.net/web2/dlna/
  http://home.net/web2ilo/login.html
  </code></pre>
  
  <h1>My problem</h1>
  
  <p>That nearly works but the web applications tend to rewrite URLs so that after I login to, respectively:</p>
  
  <pre><code>http://home.net/web1/phpAdmin/login.php
  http://home.net/web2ilo/login.html
  </code></pre>
  
  <p>the browser is redirected respectively to </p>
  
  <pre><code>http://home.net/phpAdmin/index.php
  http://home.net/index.html 
  </code></pre>
  
  <p>Note that the relative subpaths <strong>web1</strong> and <strong>web2ilo</strong> have gone, which logically give me a 404.</p>
  
  <h1>My config</h1>
  
  <p>So far, I've searched a lot and I tried many options in nginx without understanding too much what I was doing. Here is my config that reproduces this problem. I've left SSL out for clarity.</p>
  
  <pre><code>   server {
        listen       443 ssl;
        server_name  localhost;
  
        # SSL stuff left out for clarity 
  
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
  
        location /web1/ {
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_pass https://web1.lan/;
        }
  
  
        location /web2/ {
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_pass https://web2.lan/;
        }
  
        location /web2ilo/ {
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_pass https://web2ilo.lan/;
        }
  
    }
  </code></pre>
  
  <h1>After first answers</h1>
  
  <p>After the first couple of answers (thanks!), I realise that my setup is far from common and that I may be heading for trouble all alone.</p>
  
  <p>What would then be a better idea to access the webserver behind the firewall without touching frontend ports and domain/hostname ?</p>