1

I'm trying to use nginx to reverse proxy a specific location specification, as below:

server {
    listen 80;
    server_name example.com;

    location /example {
        proxy_pass http://localhost:8080/test;
    }
}

Now, when I try and access a resource at http://example.com/example/css/styles.css I expect it to try and access http://localhost:8080/test/css/styles.css. But alas - I get a 404 from nginx.

When I try and access http://example.com/example it shows me what's on http://localhost:8080/test (so I know the base url segment is working) minus anything being imported into that page from a relative url (e.g. styles and JS files)

How do I get the reverse proxy to work with child url segments?

Tom Byte
  • 11
  • 3
  • Add slashes at the end of `location` and `proxy_pass` parameters. – Ivan Shatsky Oct 18 '19 at 14:12
  • @IvanShatsky that seems to work, thank you! – Tom Byte Oct 18 '19 at 14:19
  • You can find more info about `proxy_pass` befavior related to slashes [here](https://stackoverflow.com/questions/53649885/a-little-confused-about-trailing-slash-behavior-in-nginx), and [here](https://stackoverflow.com/questions/54084239/proxy-pass-overwrites-the-url-changed-by-rewrite-directive/) is my detailed explanation of some `proxy_pass` behavior aspects. – Ivan Shatsky Oct 19 '19 at 09:30

1 Answers1

0

Per Ivan's comment on the original question, here is a working configuration with trailing slashes added:

server {
    listen 80;
    server_name example.com;

    location /example/ {
        proxy_pass http://localhost:8080/test/;
    }
}
Allen Ellis
  • 269
  • 2
  • 9