Virtual hosts in Caddy?

Hello

I have a local web-application running on 127.0.0.1:8080. Now I am wondering if it’s possible to configure some kind of virtual host in Caddy like this:

127.0.0.1:8080 mysite.test

Preferably it should also be able to redirect to subdomains like this:

127.0.0.1:8080 mysite.test
127.0.0.1:8080 a.mysite.test
127.0.0.1:8080 b.mysite.test
127.0.0.1:8080 c.mysite.test

Is it possible?

I don’t understand what you’re asking, really.

What do you mean by “redirect”? That has a very specific meaning in HTTP, i.e. responding with a Location header, telling the browser to make a new request at a different location.

Please fill out the help thread template.

Redirect instead is the wrong term I used.
I want to emulate the behavior of CNAME’s.

I still don’t really understand. Caddy isn’t a DNS server. What do you want to do with these domain aliases? Please elaborate.

I think you’re looking for this in the docs:

Please, for next time, fill out the help thread template. We would’ve saved time that way.

I am actually just searching for the alternative to Apache’s /etc/hosts-file in Caddy.

Well, that’s not a thing, because Caddy is not a DNS server, like I said. It’s an HTTP server. Caddy handles HTTP requests, looks at the hostname in the request, and routes based on that (that’s a huge oversimplification, but I’m not sure how else to get the idea across).

To be clear, /etc/hosts is not an apache thing, it’s a Linux thing. It just tells your system how to resolve certain hosts that you specify to an IP address, as an override. Windows has the same in C:\Windows\System32\hosts if I remember the path correctly.

1 Like

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