Configure HAProxy backend to a url with a subdirectory?
-
I've been able to get haproxy to proxy web requests to urls that work based purely on the alias running at the webroot. For example urls like the following:
homeassistant.mydomain.com
guacamole.mydomain.com
pfsense.mydomain.comWhat I don't know how to do is configure a backend that'll forward to a url with a subdirectory underneath. For example:
plex.mydomain.com/web
octoprint.mydomain.com/3dprinterHow do I get the proxy server to proxy a web request to those URLs? I don't want to have to remember to append the /web or /3dprinter to the end of my urls. I'd like to just go to plex.mydomain.com or octoprint.mydomain.com.
Is this possible?
-
@dutsnekcirf
Basically there is no need to run a website within a subdirectory behind a reverse proxy. This makes things more complicated.However, HAproxy is able to insert a string at the beginning of the path. You can use "http-request set-path" to do this.
You can set it in the frontend or backend. The preferred method depends on your setup.
Add an action, select "http-request set-path" and enter "/web/%[path]" below. This assumes that the website has further subdirectories.However, with this, the additional path is inserted into all requests.If your website send URLs to call to the client, which already inlcludes the "/web/", you have to bind this action to an ACL to ensure it is not applied in this case.
-