Serving multiple file_servers on the same Port

1. The problem I’m having:

Given a folder with 2 subfolders in it called /site_1 and /site_2 each being a static HTML page respectively.

folder
	- site_1
	- site_2

I want to be able to access site_1 when a request is made to http://localhost:3000/ and I want to show site_2 when a request is made it http://localhost:3000/admin.

I am able to access site_1 over http://localhost:3000/, however I am not able to access site_2 on http://localhost:3000/admin.

2. Error messages and/or full log output:

None

3. Caddy version:

4. How I installed and ran Caddy:

RUN apk add caddy

a. System environment:

Docker

b. Command:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

d. My complete Caddy config:

:3000  {
  root * /site/selfhost-web
  file_server

	handle_path /admin* {
		root * /site/sh-admin
    file_server
	}

	handle_path /backend* {
		reverse_proxy localhost:3170
	}
}

5. Links to relevant resources:

What do you mean by “not able to access”? What error are you seeing, exactly? Make a request with curl -v and show what you get.

I suggest structuring your config like this:

:3000 {
	handle_path /admin* {
		root * /site/sh-admin
		file_server
	}

	handle_path /backend* {
		reverse_proxy localhost:3170
	}

	handle {
		root * /site/selfhost-web
		file_server
	}
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.