Serve two separate hosts (IP's) on the same lan

1. My Caddy version (caddy -version): V1

2. How I run Caddy: Windows Service

System environment: Windows 10 pro

3. The problem I’m having: First of all, I am very new to all of this and really have no idea if this is possible.

I’m running Caddy V1 on my main server at home (working just fine). I have another server (on the same Lan) which manages media etc. My query is: Can I serve the secondary (Media) server from the main server via the Caddyfile or must I run a second instance of Caddy on the second server but using the same domain/sub domain - eg mainserver.domain.com on one host and 2ndserver.domain.com on the other host (don’t really want to pay for another domain name). If so could you give advice on how to set up the caddyfile(s) please

thanks jordy

I think the easiest approach would be to have one server be the sole entrypoint for connections, then just proxy any requests to the other server.

It might look something like this, just spitballing based on what you described:

mainserver.domain.com {
    root /var/www/mysite
}

secondserver.domain.com {
    proxy / http://192.168.0.150 {
        transparent
    }
}

Caddy can manage the certificates for both sites. Note that the traffic between your servers will be unencrypted. Be aware that if someone has access to your home network, then they could sniff the requests between your two servers. In practice this usually isn’t an issue, just don’t give your Wi-Fi password to people you don’t trust! :stuck_out_tongue:

2 Likes

Excellent! That what I was looking for. I’ve looked at many examples of caddyfile but never seen one with a local IP as the destination.

Just so I’m clear, does “root /var/www/mysite” apply to windows? it looks a little linux to me…

Many Thanks

jordy

Yeah, I just assumed a posix path. You can use a windows path too.

You said you already have a working Caddy instance on your main server, you’ll just need to add a site block to proxy to your other server, and your existing site should stay working the same.

1 Like

Cheers for the help

jordy

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