proxy_pass works on main page but not other pages

Francis Daly francis at
Tue Nov 1 23:35:35 UTC 2022

On Sun, Oct 30, 2022 at 11:56:39AM -0600, Brian Carey wrote:

Hi there,

> Thinking it through though I think my solution is bad since it implies a
> dependency between the urls defined in the program and the location used in
> nginx, ie. they must match and the program cannot be proxied at an arbitrary
> location.

if you have a "back-end" at, that is
reverse-proxied behind the public-facing using
the "normal" nginx config fragment

    location /one/ { proxy_pass; }

then the client browser making the requests does not know that there is
a back-end service.

When the client requests, nginx will
ask for, and will send the
response http headers and body content back to the client.

If that response contains links or references of the form "three.jpg"
or "./three.jpg", then the client will make the next request for, which will get to nginx, which will know
to proxy_pass to the same back-end service, and all will probably work.

If the response contains links of the form "/three.jpg", then the
client will make the next request for,
which will get to nginx but will probably not get a useful response,
because nginx knows that it must not proxy_pass to the same back-end
because the local part of the request does not start with /one/. The
user will probably see an error or something that looks broken.

If the response contains links of the form, then the client will presumably
fail to resolve the hostname, and the user will
probably see an error.

> So hopefully there is a better solution than the one I found. I
> hope I'm not asking too many questions.

Whether or not a particular back-end can be reverse-proxied easily,
or can be reverse-proxied easily at a different local part of the url
hierarchy from where it thinks it is installed, it mostly down to the
back-end application to decide.

In general (and there are exceptions), nginx can readily rewrite the
http response headers, and cannot readily rewrite the http response body,
in order to adjust links or references to other internal resources.

If you control the back-end service, and you know that you want to
reverse-proxy it behind, you will probably
find it easier to work with, if you can install the back-end service

That would make the first two forms of links "Just Work"; and the third
(full-url) form is usually easier to recognise and replace.

> > > I am able to use proxy_pass to forward https:/ to
> > > the main page of my app. The problem is that all of the links in the
> > > app result in a page not found error from the apache server handling
> > > requests to /. So it seems like the port number information is
> > > somehow being lost in translation?

More likely, I guess, is that the links are of the second form, to
"/three.jpg" instead of the "three.jpg".

But it could also be related to what the initial request from the client
was -- "/striker" and "/striker/" are different, and I suspect you should
use the with-trailing-slash version in your config "location" line.

But if you already have a working configuration, that's good!


Francis Daly        francis at

More information about the nginx mailing list