Simplify Caddyfile

1. Caddy version (caddy version):

Latest

2. How I run Caddy:

windows command line

a. System environment:

windows

b. Command:

caddy.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

server.net:80 {
root * /www/
file_server
}
server.net:443 {
root * /www/
file_server
}
server.tk:80 {
root * /www/
file_server
}
server.tk:443 {
root * /www/
file_server
}
server.ml:80 {
root * /www/
file_server
}
server.ml:443 {
root * /www/
file_server
}
www.server.net:80 {
    redir * https://domain.net{uri}
}
www.server.net:443 {
    redir * https://domain.net{uri}
}
www.server.tk:80 {
    redir * https://domain.net{uri}
}
www.server.tk:443 {
    redir * https://domain.net{uri}
}
www.server.ml:80 {
    redir * https://domain.net{uri}
}
www.server.ml:443 {
    redir * https://domain.net{uri}.

3. The problem I’m having:

How can I simplify my caddyfile above?

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Please run caddy version to find out, exactly. More than once, users have said “latest” when it wasn’t actually the latest, causing confusion.

Just list out all the domains like this:

server.net, server.tk, server.ml {
	root * /www/
	file_server
}

www.server.net, www.server.tk, www.server.ml {
	redir https://domain.net{uri}
}
2 Likes

Hello, my Caddy version is v2.4.3

So I don’t have to worry about listing the ports anymore? 80, 443

Nope, you never needed to. See the docs:

Didn’t seem to work without putting the ports

What’s your evidence? What’s in your logs?

I wasn’t able to access the domain name remotely any longer.

That’s not enough information for us to help you. Be specific. Show actual evidence with logs and requests with curl -v, etc.

Does this help?

2021/08/11 23:50:16.974 INFO tls.issuance.acme done waiting on internal rate limiter {“identifiers”: [“www.domain.net,www.domain.tk,www.domain.ml”], “ca”: “https://acme.zerossl.com/v2/DV90”, “account”: “”}
2021/08/11 23:50:17.243 ERROR tls.obtain could not get certificate from issuer {“identifier”: “domain.net,domain.tk,domain.ml”, “issuer”: “acme.zerossl.com-v2-DV90”, “error”: “HTTP 400 urn:ietf:params:acme:error:rejectedIdentifier - Invalid DNS identifier [domain.net,domain.tk,domain.ml]”}
2021/08/11 23:50:17.244 ERROR tls.obtain will retry {“error”: “[domain.net,domain.tk,domain.ml] Obtain: [domain.net,domain.tk,domain.ml] creating new order: request to https://acme.zerossl.com/v2/DV90/newOrder failed after 1 attempts: HTTP 400 urn:ietf:params:acme:error:rejectedIdentifier - Invalid DNS identifier [domain.net,domain.tk,domain.ml] (ca=https://acme.zerossl.com/v2/DV90)”, “attempt”: 1, “retrying_in”: 60, “elapsed”: 4.2334171, “max_duration”: 2592000}
2021/08/11 23:50:17.431 ERROR tls.obtain could not get certificate from issuer {“identifier”:

You need spaces between the domains, after the commas, as I showed above. Whitespace is significant in the Caddyfile, because it’s used for tokenizing arguments.

Basically, Caddy, parsed domain.net,domain.tk,domain.ml as if it was one whole domain, because there’s no spaces.

Okay, lets get back to basics for a sec. I’m running caddy on a Windows 2016 Server.

If I do this;
server.tk:80 {
root * /www/
file_server
}
server.tk:443 {
root * /www/
file_server
}

I can access the server remotely http://server.tk and the subfolders in the root folder

but if I do this;
server.tk {
root * /www/
file_server
}

I can still access the server http://server.tk root but don’t have access to the subfolders. http://server.tk/subfolder for example

If you don’t specify the ports, Caddy will issue a redirect from HTTP to HTTPS, to make sure the client is connecting securely. There should be no issue accessing any subfolders etc.

Do you actually have a good reason for requiring HTTP access?

Once again, please be specific. Show us evidence. Use curl -v to make requests to your server (curl is available in Windows too) which will give you something you can copy and paste to show us.

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