0

Is it possible to forward http://example.com to http://example.com:5000/foo?

I tried using proxy_pass to forward requests to port 5000:

location / { 
    proxy_pass http://127.0.0.1:5000/;
} 

Which works as expected. However, if I want to forward requests to /foo, I can't just change the proxy_pass to proxy_pass http://127.0.0.1:5000/foo/ since it wouldn't be able to find the static files.

So I then tried to use try_files in hopes to serve the static files correctly:

location / {
    try_files $uri /foo/;
}

location /foo/ { 
    proxy_pass http://127.0.0.1:5000/;
}

But that wouldn't work either since the resources are under port 5000. Any help?

Mr. 14
  • 9,228
  • 6
  • 37
  • 54
  • Can you change the application running on port 5000 to expect the base url as `/foo`? – Tarun Lalwani Oct 21 '17 at 13:12
  • @TarunLalwani I don't think that's an option since I'll have multiple sub folders on port 5000 that I'd want to forward to – Mr. 14 Oct 21 '17 at 13:30
  • Then you would need to do something like below https://stackoverflow.com/questions/46610662/nginx-reverse-proxy-with-different-context-path/46612478#46612478 – Tarun Lalwani Oct 21 '17 at 13:36

0 Answers0