10

"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.)

oguz ismail
  • 1
  • 16
  • 47
  • 69
NtlX
  • 103
  • 1
  • 1
  • 4

3 Answers3

8

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
cameck
  • 2,058
  • 20
  • 32
Jens
  • 20,533
  • 11
  • 60
  • 86
4

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)

3

You should be able to do this

https://example.com:4443 {

# config info

}
Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • 2
    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. – NtlX Jul 19 '18 at 12:44