nginx Reverse Proxy locations and subfolder path

Started by Mks, Today at 01:28:04 PM

Previous topic - Next topic
Dear all, I've a pretty simple use case but whatever I've tried it did not work.

Situation:
Two server with web-application served on different ports:
server1.domain.internal:8001
server2.domain.internal:8002

My goal is to setup a reverse proxy and serve the applications via different path, e.g

myapps.domain.internal/app1 --> server1.domain.internal:8001
myapps.domain.internal/app2 --> server2.domain.internal:8002


I know the basics about nginx, but even with the easiest application it doesn't work, either pictures are missing, wrong formatting, parts of the page are missing.

Config NGINX:
  • Server: myapps.domain.internal with 2 Location
  • Location1: URLPattern /app1
  • Location2: URLPattern /app2
  • Upstream Server and Upstream are defined

I did some research but no solution works, may someone has an idea, Thanks

 


Today at 01:54:07 PM #1 Last Edit: Today at 01:57:46 PM by meyergru
The reverse proxy cannot handle all of what is needed when you want to present two websites via different URI paths.

Say, your backend server creates web pages containing embedded image links with the absolute path itself knows about, like, when server1.domain.internal shows a snippet of: <img src="/images/xyz.jpg">. Since the reverse proxy does not change the content of the html, it will then not reference https://myapps.domain.internal/app1/image/xyz.jpg, but https://myapps.domain.internal/image/xyz.jpg, which is wrong. Same goes for CSS and Javascript snippets.

And that does not even consider cases where your internal server creates absolute links like <img src="https://server1.domain.internal:8001/images/xyz.jpg">, like many applications do.

So, in order to make this work, the paths may not change unless you can configure your backend application to use either relative paths only or you can configure its "real" URL to be https://myapps.domain.internal/app1/.

An alternative remedy could be to use app1.domain.internal and app2.domain.internal, so your URI paths do not change (but that only addresses the "absolute path", not the "full URL"  problem). The reverse proxy differentiates the backend "by name" instead of "by path" in that case.
Intel N100, 4* I226-V, 2* 82559, 16 GByte, 500 GByte NVME, ZTE F6005

1100 down / 800 up, Bufferbloat A+

Many web applications have the concept of a base URL that can be configured. In this particular case you would need to set these to myapps.domain.internal/app1 and myapps.domain.internal/app2, respectively so all embedded assets and internal links point to the correct address.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)