'Reverse proxy multiple local servers under subdirectories of web server?
I have multiple HTTP servers running on multiple machines within a LAN:
- server1: 192.168.1.2:80
- server2: 192.168.1.4:8000
I have no control over the page structure or content. The pages have relative links and scripts (JS) that dynamically load other pages in the server.
The goal is to create a single web server that exposes these local servers to the web like so:
- server1: https://website.com/server1/
- server2: https://website.com/server2/
The structure of each server should appear to have moved under /server on the web server. What's a simple way to do this? I'm trying to avoid writing custom server logic.
I've tried nginx's proxy_pass but this doesn't work for relative links:
server {
listen 8001;
location ~ ^/server1/(.*)$ {
proxy_pass http://192.168.1.9:80/$1;
}
location ~ ^/server2/(.*) {
proxy_pass http://192.168.1.12:80/$1;
}
}
I've tried looking at the Referer header and redirecting to the correct subdirectory but HTTP 3xx is not correctly handled by the JS in the local servers. (ref)
alias is not an option as the URL structure of the local servers may overlap with each other.
Port forwarding is a no-go as I don't have access to the router.
PS. Maybe relevant, but the machine hosting the web server does not have a public IP. I am exposing it via an ngrok tunnel.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
