title: Nginx reverse proxy 404 on static files
body: <p>I am looking to reverse proxy one url/path to different ports on an end point that represent different servers hosting their own web apps. </p>
  
  <p>I have the proxy_pass working, but the static files fail because the resources are relative their instance. </p>
  
  <p>I have for example - server_name = myproxy.com:</p>
  
  <pre><code>location /app1/{
      proxy_pass: http://192.168.1.1:8080/;
      proxy_set_header Host 192.168.1.1;
  }
  location /app2/{
      proxy_pass: http://192.168.1.1:8081/;
      proxy_set_header Host 192.168.1.2;
  }
  location /{
      proxy_pass: http://192.168.1.1:8080/;
      proxy_set_header Host 192.168.1.1;
  }
  </code></pre>
  
  <p>The reverse-proxy works great as mentioned, except for the static files associated with the app2. App1 static files work fine, but App2 static files result in a 404. Which make sense, because App1 resource files are located at <code>/assets/app1.css</code> this works because I have a redirect for location <code>/</code> in place that resolves back to App1 but App2 resource files, which are totally different <code>/assets/app2.css</code> result in 404. </p>
  
  <p>So, is there a way to rewrite App2 static requests from <code>/assets/app2.css</code> to their respective proxy location? something like:</p>
  
  <pre><code>location /app1/{
      proxy_pass: http://192.168.1.1:8080/;
      proxy_set_header Host 192.168.1.1;
  }
  location /app2/{
      proxy_pass: http://192.168.1.1:8081/;
      proxy_set_header Host 192.168.1.2;
  
      *rewrite app2 static urls frome /assets/* to /app2/assets/*
  }
  location /{
      proxy_pass: http://192.168.1.1:8080/;
      proxy_set_header Host 192.168.1.1;
  }
  </code></pre>