Reverse Proxy Nginx with Subdomain

Started by maraD, March 24, 2024, 08:24:39 PM

Previous topic - Next topic
Hello dear Community,

I need your help with the topic of Reverse Proxy Nginx! 😄

Here's the task I need to tackle: :-\

I receive the following client requests:

https://x1.domain.io/zs/ef/x/ <--- The request comes in this format.

What needs to be done: The subdomain determines which website will be opened.

For all requests, the index.htm must always be accessible at domain.io/zs/ef/x/zs/ef/x/.

Only one server is defined as the upstream server. It has the corresponding index.htm and associated files in /var/www/x1.

This means:

Request A:
https://x1.domain.io/zs/ef/x/

Retrieves data from the WebRoot: /var/www/x1/

Request B:
https://x2.domain.io/zs/ef/x/

Retrieves data from the WebRoot: /var/www/x2/

I've set up the default configuration in Nginx, it's running, and the page is being displayed. 😄
The location is "/", so when https://x1.domain.io/zs/ef/x/ is accessed, the page is displayed as desired. MEGA!

A domain is set up, and the subdomain names are entered as alternative names in the certificate. 😉

The logic above doesn't work as intended. Since the path in the webroot is decisive and not the subdomain, this needs to be reversed. ::) ??? :o

Thanks for any input!






Hi
I'm not sure that I fully understand, but if you want to do this through GUI, you will have to make two servers:
x1.domain.io
x2.domain.io
(upstream may be left alone)
To add a folder to URL, you can add two rewrite rules like:
rewrite ^(/zs/ef/x/)(.*) $1x1/$2 last;
rewrite ^(/zs/ef/x/)(.*) $1x2/$2 last;

and add them to the appropriate servers.
but I'm really not sure I understood the intent correctly