1. The problem I’m having:
I already posted this problem, but found a workaround before.
Release old bindings when HTTPS redirects are disabled - Help - Caddy Community
Now the same problem appears, but the workaround is no longer effective after upgrading from caddy 2.4.7 to 2.7.5
I wanted to change the “listen”-field on a server to no longer listen on all IPs on the ports 80 and 443, but instead listen on all IPs on port 80 and one specific IP on port 443.
Previous configuration:
"listen": [
"0.0.0.0:80",
"0.0.0.0:443"
]
Target state:
"listen": [
"0.0.0.0:80",
"10.33.40.173:443"
]
But when I try to patch the config I get an error message saying the port is already binded:
-> % curl -X PATCH -H "Content-Type:application/json" --unix-socket /run/caddy-standard.sock -H "Host: localhost" http://@/config/apps/http/servers/external-interfaces/listen --data '["0.0.0.0:80", "10.33.40.173:443"]'
{"error":"loading new config: http app module: start: listening on 10.33.40.173:443: listen tcp 10.33.40.173:443: bind: cannot assign requested address"}
On v2.4.7, I used a workaround where I first patched the config to listen only on port 80 and then add the desired IP for port 443, but this no longer seems to work anymore as it results in the same error.
The netstat
output also confirms that caddy listens on 443 even when the caddy config is set to only listen to port 80:
netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 :::80 :::* LISTEN 5043/caddy
tcp 0 0 :::443 :::* LISTEN 5043/caddy
udp 0 0 :::443 :::* 5043/caddy
...
Maybe there is a problem with unbinding the port after the caddy config is changed?
2. Error messages and/or full log output:
{"error":"loading new config: http app module: start: listening on 10.33.40.173:443: listen tcp 10.33.40.173:443: bind: cannot assign requested address"}
3. Caddy version:
v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q=
4. How I installed and ran Caddy:
I have the binary installed on the device
a. System environment:
Debain 10 without systemd, arm64 architecture
b. Command:
/usr/bin/caddy run --pidfile /run/caddy-standard.pid --resume --environ --envfile /etc/caddy/caddy-standard.env```
d. My complete Caddy config:
{
"admin": {
"listen": "unix//run/caddy-standard.sock",
"origins": [
"localhost"
]
},
"apps": {
"http": {
"servers": {
"external-interfaces": {
"automatic_https": {
"disable_redirects": true
},
"listen": [
"0.0.0.0:80"
],
"routes": [
{
"@id": "askendpoint",
"handle": [
{
"handler": "static_response",
"status_code": "200"
}
],
"match": [
{
"path": [
"/ask*"
]
}
]
},
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "localhost:7000"
}
]
}
]
}
],
"tls_connection_policies": [
{
"protocol_min": "tls1.2"
}
]
}
}
},
"pki": {
"certificate_authorities": {
"device_ca": {
"intermediate_common_name": "Test Intermediate CA",
"root_common_name": "Test Root CA"
}
}
},
"tls": {
"automation": {
"on_demand": {
"ask": "http://localhost/ask",
"rate_limit": {
"burst": 5,
"interval": "1m"
}
},
"policies": [
{
"issuers": [
{
"ca": "device_ca",
"module": "internal"
}
],
"key_type": "rsa2048",
"on_demand": true
}
]
}
}
}
}
5. Links to relevant resources:
https://caddy.community/t/release-old-bindings-when-https-redirects-are-disabled/21891/7