nginx proxy pass only works for root location

Maxim Dounin mdounin at mdounin.ru
Fri Nov 19 01:39:02 UTC 2021


Hello!

On Thu, Nov 18, 2021 at 05:31:27PM -0500, gunitinug wrote:

> Maxim Dounin Wrote:
> -------------------------------------------------------
> > Hello!
> > 
> > On Thu, Nov 18, 2021 at 05:51:08AM -0500, gunitinug wrote:
> > 
> > > Hello. I posted a question:
> > > 
> > >
> > https://unix.stackexchange.com/questions/678060/nginx-proxy-pass-only-
> > works-for-root-location
> > 
> > First of all you may want to define "won't work".  What exactly 
> > happens, what goes wrong?
> > 
> > Note that in general there are no problems with proxying in nginx: 
> > it will happily get a request from the client and pass it the 
> > backend server, and will return the response from the backend 
> > server to the client.
> > 
> > But proxying, especially if you are trying to proxy with changed 
> > URI, might result in incorrect resulting page if your backend 
> > server uses absolute links in responses.  Or your backend server 
> > might not like the request coming from nginx and will try to 
> > redirect the client.
> > 
> > Most common issue which happens when proxying is wrong URLs in 
> > redirections returned by the backend server.  This is something 
> > nginx is usually able to fix itself with the default settings of 
> > the proxy_redirect directive.  In complex cases some adjustment 
> > might be needed though (see http://nginx.org/r/proxy_redirect for 
> > details).
> > 
> > Another common issue is wrong links in the HTML pages 
> > returned.  In some cases these can be fixed with sub_filter 
> > (http://nginx.org/r/sub_filter), but usually a better idea is to 
> > configure your backend server to return correct links instead.
> 
> Loading of the app in browser fails. 
> 
> I checked the console and it says:
> 
> Loading failed for the <script> with source
>http://my_vps_public_ip/static/js/bundle.js”.
> Loading failed for the <script> with source
>http://my_vps_ip_public_ip/static/js/0.chunk.js”. ecapp:30:1
> Loading failed for the <script> with source
>http://my_vps_ip_public_ip/static/js/main.chunk.js”. ecapp:30:1

So it looks like a problem with links in the response.

As previously suggested, recommended approach would be to configure 
your backend to return links with correct prefix.  Refer to your 
app documentation on how to do it.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list