<p>I'm trying to use nginx to reverse proxy into kubernetes pods running various web apps. My issue is that I can only proxy when location is set to <code>/</code> and not <code>/someplace</code></p>

<p>I know the internal IPs are working because both web apps load successfully when I use them with <code>location /</code>, and I can curl the webpages internally. </p>

<p>What I would like to happen</p>

<p><a href="http://ServerIP/app1" rel="nofollow noreferrer">http://ServerIP/app1</a> to route to <a href="http://Pod1IP:3000" rel="nofollow noreferrer">http://Pod1IP:3000</a>
<a href="http://ServerIP/app2" rel="nofollow noreferrer">http://ServerIP/app2</a> to route to <a href="http://Pod2IP:80" rel="nofollow noreferrer">http://Pod2IP:80</a></p>

<p>In this manner I could easily run all my apps on the same port. </p>

<p>What I believe is happening
<a href="http://ServerIP/app1" rel="nofollow noreferrer">http://ServerIP/app1</a> --> httpL//Pod1IP:3000/app1</p>

<p>I tried solving this by doing a rewrite of the URI like below, that resulted in a blank page loading when I tried to access <code>/app1</code> </p>

<pre><code>server {
listen 80;

location = /app1/ {
  rewrite ^.*$ / break;
  proxy_pass http://10.82.5.80:80;
  }
location / {
  proxy_pass http://10.106.228.213:15672;
  }
}
</code></pre>

<p>Any ideas where I messed up?</p>

<p>The webapp I am trying to use is called RabbitMQ UI. To try and debug my situation I curled three different URLs to see what nginx was responding with.</p>

<p>Curling the <code>/</code> loads the correct html page, and it works in the browser.</p>

<p><code>curl http://10.82.5.80/</code></p>

<pre><code>&lt;!doctype html&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;RabbitMQ Management&lt;/title&gt;
    &lt;script src="js/ejs-1.0.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery-1.12.4.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/sammy-0.7.6.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/json2-2016.10.28.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/base64.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/global.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/main.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/prefs.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/formatters.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/charts.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;link href="css/main.css" rel="stylesheet" type="text/css"/&gt;
    &lt;link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/&gt;

&lt;!--[if lte IE 8]&gt;
    &lt;script src="js/excanvas.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;link href="css/evil.css" rel="stylesheet" type="text/css"/&gt;
&lt;![endif]--&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="outer"&gt;&lt;/div&gt;
    &lt;div id="debug"&gt;&lt;/div&gt;
    &lt;div id="scratch"&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Curling <code>/rabbitmq</code> returns not found or Moved Permanently</p>

<p><code>curl http://10.82.5.80/rabbitmq</code></p>

<pre><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
&lt;body bgcolor="white"&gt;
&lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
&lt;hr&gt;&lt;center&gt;nginx/1.10.3 (Ubuntu)&lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Curling the <code>/rabbitmq/</code> location gives the correct page, but loads a blank in the browser. I think this is because the browser cannot reference the js files present in the html doc? </p>

<p>curl <a href="http://10.82.5.80/rabbitmq/" rel="nofollow noreferrer">http://10.82.5.80/rabbitmq/</a></p>

<pre><code>&lt;!doctype html&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;RabbitMQ Management&lt;/title&gt;
    &lt;script src="js/ejs-1.0.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery-1.12.4.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/sammy-0.7.6.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/json2-2016.10.28.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/base64.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/global.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/main.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/prefs.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/formatters.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="js/charts.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;link href="css/main.css" rel="stylesheet" type="text/css"/&gt;
    &lt;link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/&gt;

&lt;!--[if lte IE 8]&gt;
    &lt;script src="js/excanvas.min.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;link href="css/evil.css" rel="stylesheet" type="text/css"/&gt;
&lt;![endif]--&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="outer"&gt;&lt;/div&gt;
    &lt;div id="debug"&gt;&lt;/div&gt;
    &lt;div id="scratch"&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Try adding the URL in your proxy location like this:</p>

<pre><code>location = /app1/ {
  proxy_pass http://10.82.5:80/;
}
</code></pre>

<p>Adding a trailing <code>/</code> at the end of the proxy_pass forces nginx to strip the <code>/app1</code> prefix from your requests while sending it to the backend.</p>

<p>Explanation on how it works on the official nginx page: <a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&amp;_ga=1.74997266.187384914.1443061481#proxy_pass" rel="nofollow noreferrer">http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&amp;_ga=1.74997266.187384914.1443061481#proxy_pass</a></p>

<pre><code>If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:
</code></pre>
