Multiple domains

Hello
Is it possible to host 2 domains on single server with Caddy?

Hi @ben,

You absolutely can, you just need to know how to write your Caddyfile to do that. Check out the Caddyfile docs - the Syntax section is pretty comprehensive.

For example, if you wanted to serve different websites at different domains, it’d look something like this:

mysite.com {
    root /www/mysite.com
}

sub.mysite.com {
    root /www/sub.mysite.com
    gzip
    log ../access.log
}

And serving the same website over multiple domains would look a bit like this:

localhost:2020, https://site.com, http://mysite.com {
    ...
}
4 Likes

Hi @Whitestrake,
Thank you for the answer.
I need the 1st option. Will try it soon.

Works good, thanks.
I want to add the https option. I understand that there is a problem to do it for several sites on the same server.
Does Caddy automation handle it?
TIA

HTTPS just works, don’t even think about it. :wink:

1 Like

Thank you Matt, but when I started CADDY 1st time, it tried to connect automatically to Let’s Encrypt. the process did not go well, as the net firewall caused problems, and I hop that I corrected it now.
How do I activate this automation again?
I need certificates for the 2 sites
Do I have to add something in the caddyfile?

Ben,

You don’t need to add anything for https to work. Just restart caddy and it’ll request certificates for all sites!

1 Like

Thank you Fredrik,
CADDY and the automatic privacy/encryption process are new for me, so I have beginner questions…
Please check the question I put about privacy, maybe you can help it too, as I still doen’t work

Hi all,

Is it possible to have entirely separate domains in a single Caddyfile? For example:

mysite.com {
    root /www/mysite.com
}

myothersite.com {
    root /www/myothersite.com
    gzip
    log ../access.log
}

So far I haven’t gotten this to work.

This should work perfectly. Caddy can serve multiple domains.

What errors are you recieving?

Hm, you’re right @tobya, it does work! I must have been doing something else wrong. Not sure exactly what yet, but I’ll report back if I figure it out.

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