title: How Nginx proxy handle internal redirection
body: <p>I have a problem to understand how nginx proxy_pass will handle the redirection after the URL getting rewrite.</p>
  
  <p>What I have is <code>localhost:8080/foo/log</code> will automatically redirect to <code>localhost:8080/foo/login</code>. Once you enter the right credentials it will redirect back to <code>localhost:8080/foo/log</code></p>
  
  <pre><code>localhost:8080/foo/log -----&gt; localhost:8080/foo/login
  </code></pre>
  
  <p>I have a nginx proxy server to change my URL from <code>localhost:8080/foo/log</code> to <code>localhost/web/foo/log</code> with following configuration </p>
  
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      server_name localhost;
  
      root /var/www/html;
      index index.html;
  
      location /web/foo {
          proxy_pass http://localhost:8080/;
          rewrite ^/web/foo(.*) /foo$1 break;
      }
  
      location /web/bar {
          proxy_pass http://localhost:8081/;
          rewrite ^/web/bar(.*) /bar$1 break;
      }
  }   
  </code></pre>
  
  <p>With this proxy config, I am ok to see<code>localhost/web/foo/log</code> proxy from  <code>localhost:8080/foo/log</code> without enabling login redirection. If I enabled login, I always get <code>localhost/web/foofoo/login</code>.</p>
  
  <p>I am wondering how can I get <code>localhost/web/foo/login</code> proxy from <code>localhost:8080/foo/login</code> ?</p>