title: nginx reverse proxy - how to serve multiple apps
body: <p>I am trying to build a reverse proxy with nginx to make all Is in my project reachable from single address.
  For a single service the configuration below works without problem</p>
  <p><code>/etc/nginx/sites-enabled/reverse-proxy.conf</code></p>
  <pre><code>server {
          listen 80;
          listen [::]:80;
          location  / {
  
          resolver 127.0.0.1;
          allow &quot;x.x.x.x&quot;;
          deny   all;
          proxy_pass http://consul:8500;
      }
  
  }
  </code></pre>
  <p>So when I call server's ip <code>x.x.x.x</code> in my browser I see the Consul UI and the URL showing <code>x.x.x.x/ui/dc1</code>. Besides that, I see that the UI did requests for asset files successfully.</p>
  <p>My question; is it possible two host different services on the same server and just reference to them with different location? For example, if I want to include Vault UI then I would think of doing something like this:</p>
  <pre><code>server {
          listen 80;
          listen [::]:80;
          location  /consul {
  
          resolver 127.0.0.1;
          allow &quot;x.x.x.x&quot;;
          deny   all;
          proxy_pass http://consul:8500;
      }
  
          location  /vault {
  
          resolver 127.0.0.1;
          allow &quot;x.x.x.x&quot;;
          deny   all;
          proxy_pass http://vault:8200;
      }
  
  }
  </code></pre>
  <p>However I am not sure if this could be done this way. The farest I got, is to open the Consul UI with all other sub requests not found (i.e. loading assets).</p>
  <hr />
  <p><strong>UPDATE</strong></p>
  <p>I think my problem is that I am wrongly using <code>location</code> and <code>proxy_pass</code></p>
  <p>observing the first configuration (which is working)</p>
  <pre><code>server {
          listen 80;
          listen [::]:80;
          location  / {
  
          resolver 127.0.0.1;
          allow &quot;x.x.x.x&quot;;
          deny   all;
          proxy_pass http://consul:8500;
      }
  
  }
  </code></pre>
  <p>If I look at the curl command <code>curl localhost -L -vvvv</code></p>
  <pre><code>*   Trying 127.0.0.1:80...
  * TCP_NODELAY set
  * Connected to localhost (127.0.0.1) port 80 (#0)
  &gt; GET / HTTP/1.1
  &gt; Host: localhost
  &gt; User-Agent: curl/7.68.0
  &gt; Accept: */*
  &gt; 
  * Mark bundle as not supporting multiuse
  &lt; HTTP/1.1 301 Moved Permanently
  &lt; Server: nginx/1.18.0 (Ubuntu)
  &lt; Date: Fri, 10 Jul 2020 16:24:38 GMT
  &lt; Content-Type: text/html; charset=utf-8
  &lt; Content-Length: 39
  &lt; Connection: keep-alive
  &lt; Location: /ui/
  &lt; 
  * Ignoring the response-body
  * Connection #0 to host localhost left intact
  * Issue another request to this URL: 'http://localhost/ui/'
  * Found bundle for host localhost: 0x557b754549e0 [serially]
  * Can not multiplex, even if we wanted to!
  * Re-using existing connection! (#0) with host localhost
  * Connected to localhost (127.0.0.1) port 80 (#0)
  &gt; GET /ui/ HTTP/1.1
  &gt; Host: localhost
  &gt; User-Agent: curl/7.68.0
  &gt; Accept: */*
  &gt; 
  * Mark bundle as not supporting multiuse
  &lt; HTTP/1.1 200 OK
  &lt; Server: nginx/1.18.0 (Ubuntu)
  &lt; Date: Fri, 10 Jul 2020 16:24:38 GMT
  &lt; Content-Type: text/html; charset=utf-8
  &lt; Content-Length: 7806
  &lt; Connection: keep-alive
  &lt; Accept-Ranges: bytes
  &lt; Last-Modified: Fri, 10 Jul 2020 07:37:44 GMT
  &lt; 
  &lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot; class=&quot;ember-loading&quot;&gt;
  ...
  </code></pre>
  <p>and I can see the html already. However, if I changed the conf file to this:</p>
  <pre><code>server {
          listen 80;
          listen [::]:80;
          location  /consul/ {
  
          resolver 127.0.0.1;
          allow &quot;x.x.x.x&quot;;
          deny   all;
          proxy_pass http://consul:8500;
      }
  
  }
  </code></pre>
  <p>and then try to call it like <code>curl localhost/consul -L -vvvv</code>, I get the following:</p>
  <pre><code>*   Trying 127.0.0.1:80...
  * TCP_NODELAY set
  * Connected to localhost (127.0.0.1) port 80 (#0)
  &gt; GET /consul HTTP/1.1
  &gt; Host: localhost
  &gt; User-Agent: curl/7.68.0
  &gt; Accept: */*
  &gt; 
  * Mark bundle as not supporting multiuse
  &lt; HTTP/1.1 301 Moved Permanently
  &lt; Server: nginx/1.18.0 (Ubuntu)
  &lt; Date: Fri, 10 Jul 2020 16:32:35 GMT
  &lt; Content-Type: text/html
  &lt; Content-Length: 178
  &lt; Location: http://localhost/consul/
  &lt; Connection: keep-alive
  &lt; 
  * Ignoring the response-body
  * Connection #0 to host localhost left intact
  * Issue another request to this URL: 'http://localhost/consul/'
  * Found bundle for host localhost: 0x55ba7959f9e0 [serially]
  * Can not multiplex, even if we wanted to!
  * Re-using existing connection! (#0) with host localhost
  * Connected to localhost (127.0.0.1) port 80 (#0)
  &gt; GET /consul/ HTTP/1.1
  &gt; Host: localhost
  &gt; User-Agent: curl/7.68.0
  &gt; Accept: */*
  &gt; 
  * Mark bundle as not supporting multiuse
  &lt; HTTP/1.1 404 Not Found
  &lt; Server: nginx/1.18.0 (Ubuntu)
  &lt; Date: Fri, 10 Jul 2020 16:32:35 GMT
  &lt; Content-Length: 0
  &lt; Connection: keep-alive
  </code></pre>
  <p>I would appreciate any ideas on this issue</p>