Specify Caddy listening port
Asked Answered
C

3

12

"By default, Caddy will bind to ports 80 and 443 to serve HTTPS and redirect HTTP to HTTPS." (https://caddyserver.com/docs/automatic-https)

How can we change this port?

Background: In our setup, Caddy runs behind an AWS load balancer which forwards requests from port 443 to port 4443. Therefore, we would like to have Caddy listen on 4443. (We use the DNS challenge.)

Closeknit answered 6/7, 2018 at 11:43 Comment(0)
F
9

According to the documentation:

The first line of the Caddyfile is always the address of the site to serve.

In your Caddyfile:

<domain>:<port>

Example:

localhost:8080
Flimflam answered 6/7, 2018 at 11:45 Comment(2)
How do you make caddy listen on port 80 and port 443? Or at least 2 separate ports, one for HTTP and one for HTTPS?Choose
@Choose just list the hostname: localhost will listen on port 80 and 443.Dihybrid
E
8

Above answers are both good, but if you want to run on specific port and have other reverse proxy redirecting from yourdomain.com:443 to <MY_SERVER_IP>:4443, you can use global settings

{
    http_port 880
    https_port 4443
}

mydomain.com {
    ...
}

Only use this when you want your server to run on 4443 but be able to accept requests where Host: mydomain.com is present (host doesn't have :4443 port)

Euh answered 20/2, 2022 at 16:32 Comment(0)
B
3

You should be able to do this

https://example.com:4443 {

# config info

}
Botryoidal answered 6/7, 2018 at 14:36 Comment(1)
Thanks, somehow I overlooked this sentence in the caddy documentation. With this kind of configuration the certificate renewal also works behind the load balancer, even if caddy itself is not listening on port 443.Closeknit

© 2022 - 2024 — McMap. All rights reserved.