Map a subdomain to a subfolder

1. The problem I’m having:

I have an HTTP upstream application which is served from a subfolder /foo. The application is aware that its served from a subfolder so some kind of “baseURL” is in place. The app is currently reachable from the intranet via http://IP-of-the-server/foo.

The goal is to make it reachable from the internet via https://foo.domain.tld.

I managed to get it working with https://foo.domain.tld/foo, but I want to get rid of the /foo path in the domain.

2. Error messages and/or full log output:

N/A

3. Caddy version:

v2.11.2

4. How I installed and ran Caddy:

  • apt install caddy
  • Run by systemd as described in the caddy documentation

a. System environment:

  • Ubuntu 24.04.4 LTS

b. Command:

N/A

c. Service/unit/compose file:

N/A

d. My complete Caddy config:

foo.domain.tld {
	route {
		rewrite / /foo{uri}
		reverse_proxy * http://IP {
			header_up Host {host}
			header_up X-Real-IP {remote_host}
		}
	}
}

5. Links to relevant resources:

I have read The "subfolder problem", OR, "why can't I reverse proxy my app into a subfolder?" but do not know how to turn this into a working config.

You can try if it works better for you if you change that line to rewrite /foo{uri}.

Please specify which software it is. The existence of a baseurl option does not mean the application supports being served from a subfolder – sometimes it’s just a variable that is prepended to links in a notification handler like email. Consulting the documentation of such a software and, if unsuccessful, maybe their support forums/issue tracker should yield more info on whether people tried it already and if so, what worked for them.

As the linked thread specifies, HTML filtering/header rewriting is advanced stuff, and I would exhaust the easier solutions first before diving head first into some kind of config somebody posts here while you don’t understand what is happening. :slight_smile: