Else in Caddyfile

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

caddy start

a. System environment:

ubuntu 20.04 LTS server

b. Command:

caddy start

c. Service/unit/compose file:

I don’t use a compose/unit/service file

d. My complete Caddyfile or JSON config:

editid.xyz:80 {
    reverse_proxy 127.0.0.1:5555
}

3. The problem I’m having:

How can I return a file_server if someone visits from a direct ip, or from a domain not in the config?

4. Error messages and/or full log output:

No error messages, logs are disabled

5. What I already tried:

editid.xyz:80 {
    reverse_proxy 127.0.0.1:5555
}
:80 {
    file_server
}

Yes, the domain i’m using is mainly a pointless site, this was made when I was learning html and was slightly updated later on.

That’s the way to do it. What’s not working?

You’ll see logs if you run with caddy run. Using caddy start will cause logs to be thrown away. I strongly recommend using caddy run when debugging, and enabling the debug global option which might reveal some otherwise hidden errors that can be noisy.

I’d recommend writing your config like this though:

http://editid.xyz {
    reverse_proxy 127.0.0.1:5555
}
http:// {
    file_server
}
1 Like