title: Handling multiple applications from a single domain in Nginx
body: <p>Im trying to configure Nginx to handle multiple applications (backends) to work off a single domain (<code>server_name</code>) and I'm running into a weird problem.</p>
  
  <p>What I'm trying to do is,</p>
  
  <pre><code>www.test.com -------------&gt; serving the main application (127.0.0.1:7888)
               |
               -------------&gt; management application (127.0.0.1:2666)
  </code></pre>
  
  <p>The initial configuration I have is as follows,</p>
  
  <pre><code>server {
    listen  443 ssl;
    listen  [::]:443 ssl;
  
    server_name  test.com;
  
    ## SSL settings
    ssl on;
  
    location / {
      proxy_pass http://127.0.0.1:7888;
  
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
  
    location /management {
      rewrite ^/management/(.*)$ /$1 break;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
  
      proxy_pass https://127.0.0.1:2666;
    }
  }
  </code></pre>
  
  <p>This works well for the main application. It can also route to the <code>/management</code> application however it is trying to access <code>management</code> static files via the main application and it throws <code>404</code>.</p>
  
  <p>To rectify this I modified the configuration as,</p>
  
  <pre><code>server {
    listen  443 ssl;
    listen  [::]:443 ssl;
  
    server_name  test.com;
  
    ## SSL settings
    ssl on;
  
    location / {
      proxy_pass http://127.0.0.1:7888;
  
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      try_files $uri $uri/ @fallback;
    }
  
    location /management {
      rewrite ^/management/(.*)$ /$1 break;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
  
      proxy_pass https://127.0.0.1:2666;
    }
  
    location @fallback {
      proxy_pass https://127.0.0.1:2666;
    }
  }
  </code></pre>
  
  <p>Now <code>/management</code> app works well but not the main application due to the <code>try_files</code> config.</p>
  
  <p>Is there anyway to fix this issue ?</p>