Can caddy be used to direct traffic for multiple URLs to subdirectories where their websites live (html)?

1. Output of caddy version:

v2.5.2

2. How I run Caddy:

as a service on Ubuntu

a. System environment:

ubuntu 20.4 CLI

b. Command:

n/a

c. Service/unit/compose file:

 n/a

d. My complete Caddy config:

www.mysiteone.com {
reverse_proxy 127.0.0.1/siteonehtml
}

www.mysitetwo.com {
reverse_proxy 127.0.0.1/sitetwohtml
}

3. The problem I’m having:

4. Error messages and/or full log output:

no errors as I have not tried this yet

5. What I already tried:

I currently use caddy (with success) to reverse proxy a media server and some -arr apps. I’d like to host several websites on a single VPS, wondering if this could handle the traffic redirection.

6. Links to relevant resources:

I’m not sure I understand the question. Please be more specific.

Are these static sites? Are you looking for the file_server directive instead?

Yes these are static sites. I have directory 1 and inside that are all the .css and html files for a website. I have directory 2 and inside that are all the .css and .html files for another static webpage. I want caddy to receive incoming requests like my.domain1.com and send that to directory1 and then my.domain2.com gets sent to directory2 and so on.

Thus I can host multiple websites on one VPS.

My current caddy file looks like this:

https://mytest.mediaserver.net {
        # Set this path to your site's directory.
        root /home/ubuntu/sites/test-site
}

But when I run caddy, it listens on port 2019 which I think is why I cannot reach the web site.

Alright there’s a bunch of things to cover here.

That’s invalid syntax – you need to use a * matcher with root because otherwise, the root will be parsed as a path matcher. See the docs, which explain:

Also, I strongly recommend moving your sites to /srv or /var/www/html. Having your files in /home can cause permission issues, since Caddy (running as a systemd service) doesn’t run as one of the login users, it uses the caddy user.

Also, you need to enable the file_server directive for Caddy to actually serve static files.

Caddy binds to port 2019 for its admin API, which is what allows you to gracefully reload Caddy’s config, and other things.

What’s in your logs? See this page in the docs, it explains how to see Caddy’s logs:

1 Like

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