Can’t chose non-standard port

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

.\caddy_windows_amd64.exe run --config .\Caddyfile

a. System environment:

Windows Server 2016

b. Command:

.\caddy_windows_amd64.exe run --config .\Caddyfile

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

https://ummagumma.tunnel53.net:50100, https://127.0.0.1:50100 {
        log {
                output file "D:\Logs\ummagumma.log"
        }
        tls "D:\keys\ummagumma.tunnel53.net+1.pem" "D:\keys\ummagumma.tunnel53.net+1-key.pem"
        encode gzip zstd
        root * "D:\html-data"
        file_server
}

3. The problem I’m having:

It seems like Caddy wants to use port 80. Why is that…? I explicitly chose port 50100 in the Caddyfile.

4. Error messages and/or full log output:

2021/02/17 10:14:02.330 INFO    using provided configuration    {"config_file": "..\\Caddyfile", "config_adapter": ""}
2021/02/17 10:14:02.336 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": fals
e, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2021/02/17 10:14:02.337 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc00
02c6af0"}
2021/02/17 10:14:02.343 WARN    tls     stapling OCSP   {"error": "no OCSP stapling for [ummagumma.tunnel53.net 127.0.0.1]:
no OCSP server specified in certificate"}
2021/02/17 10:14:02.344 INFO    http    skipping automatic certificate management because one or more matching certifica
tes are already loaded  {"domain": "ummagumma.tunnel53.net", "server_name": "srv0"}
2021/02/17 10:14:02.345 INFO    http    skipping automatic certificate management because one or more matching certifica
tes are already loaded  {"domain": "127.0.0.1", "server_name": "srv0"}
2021/02/17 10:14:02.345 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2021/02/17 10:14:02.346 INFO    tls     cleaned up storage units
run: loading initial config: loading new config: http app module: start: tcp: listening on :80: listen tcp :80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

5. What I already tried:

I tried launching Caddy with the Caddyfile above but for some reason it doesn’t work.

I tried adding https:// in the Caddyfile but that didn’t help either.

6. Links to relevant resources:

n/a

Please upgrade to v2.3.0!

When your site qualifies for Automatic HTTPS, Caddy will set up HTTP->HTTPS redirects for you, which involves opening port 80. Caddy also uses port 80 and 443 under normal circumstances to solve the ACME HTTP and ALPN challenges, but since you’re specifying your own cert and key, this shouldn’t apply.

To turn off this behaviour, you can configure the auto_https global option, setting it to either off or disable_redirects. Setting only disable_redirects is probably enough for your usecase.

Thank you for the reminder. Done!

As per your suggestion I added the following stanza to the top of the Caddyfile:

{
	auto_https disable_redirects
}

And it seems to work fine. Thanks a lot @francislavoie!

1 Like