1. The problem I’m having:
I migrated a server from 10.1.0.172:81 to 10.1.1.1:80 and as part of having a smooth transition I setup a Caddy server to catch requests to the old IP address.
The new address is in a different network range, so I also created a reverse proxy in case people have not updated the routing on their VPNs to access 10.1.1.x
Its worth mentioning that the new server address 10.1.1.1:80 is also served by Caddy.
2. Error messages and/or full log output:
Accessing 10.1.0.172:81 always results in a redirect to 10.1.1.1.
Accessing 10.1.0.172:80 within the network results in a proxied webpage appearing as http://10.1.0.172
$ curl -IL 10.1.0.172:80
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-Length: 0
Content-Type: text/html; charset=utf-8
Date: Tue, 03 Sep 2024 07:25:36 GMT
Location: http://10.1.1.1/login?back_url=http%3A%2F%2F10.1.1.1%2F
Referrer-Policy: strict-origin-when-cross-origin
Server: Caddy
Server: Caddy
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 714a4094-6d77-4e09-b37e-88f20bfe7fc5
X-Runtime: 0.006664
X-Xss-Protection: 1; mode=block
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Length: 0
Content-Type: text/html; charset=utf-8
Etag: W/"5fbb2a59527060cc89b27ab4bb3e8a1d"
Referrer-Policy: strict-origin-when-cross-origin
Server: Caddy
Set-Cookie: _redmine_session=Nll0VU05TURma3IvU2hVVlRMTmZBK3ZWVEZ4TGFYWlBKbFdvUGkrTUtvUTQzbmxpakExM3pCSW5qVno2RXNYdlVUSEFVbEtJOUtTQ2lWb2Rhb2xldGxWREhwdVUrN3VBRGxJRnlxMmRqM2laeEV1YkxPVzc4d2NEQ09QTS9LR0dhVGhpRG5Db2x1bUdtKzNaalJCTUdnaysydjcycVNOSFVhQ0hDQXphWnpCOXV3Rk5aY1pQYjhKMVB4cy9naVRJLS1kWUNKRXJvYXNvWGZzWFVHWUJOT2RBPT0%3D--04c5525095c2d3ce2403c4020aba670f85c6e579; path=/; HttpOnly; SameSite=Lax
Vary: Accept
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: d5849379-4145-4476-b841-5ed18a42a451
X-Runtime: 0.197651
X-Xss-Protection: 1; mode=block
Date: Tue, 03 Sep 2024 07:25:36 GMT
Accessing 10.1.0.172:80 from the VPN results in a redirect to http://10.1.1.1
$ curl -IL 10.1.0.172:80
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-Length: 0
Content-Type: text/html; charset=utf-8
Date: Tue, 03 Sep 2024 07:22:53 GMT
Location: http://10.1.1.1/login?back_url=http%3A%2F%2F10.1.1.1%2F
Referrer-Policy: strict-origin-when-cross-origin
Server: Caddy
Server: Caddy
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: a33b361f-f7b8-4d8c-a682-5be3d97afb8a
X-Runtime: 0.025048
X-Xss-Protection: 1; mode=block
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Length: 0
Content-Type: text/html; charset=utf-8
Etag: W/"fc7a15cbde47db36216bbf9b4339eb77"
Referrer-Policy: strict-origin-when-cross-origin
Server: Caddy
Set-Cookie: _redmine_session=Yy92WkUxekpVYVBJb0pZTWJjUWJMMFM0SVFUc2tNci9ZZEVrck8zR0habWNZTXo4YlZxdHVvbUlIcWdpYlpjcHRLTmZxWUZBcTQ1cEhyTWg1bExXUkk2aDE3UHVmQXB2aTRDR2tUd3htT25ubHdwTWRBSExCN1p0dHcvUEpGOThFWC9HQzJzVkxyVXAyUDk4d0JoWTBuVVQ2cjVURlBRNUFwSUs2M2FWaG9xMklyUkpPeGpHbmRqb3VHK1JEYnp1LS14OS9qait5bDJpK1RNWlhXR2V4YkZBPT0%3D--a0a7a9cf52557153af67cac656baff9454a1e3f6; path=/; HttpOnly; SameSite=Lax
Vary: Accept
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 59bb10d8-c2d4-48b9-9f84-0e0cefd81d27
X-Runtime: 0.302681
X-Xss-Protection: 1; mode=block
Date: Tue, 03 Sep 2024 07:22:54 GMT
Why is it redirecting and not proxying over VPN?
3. Caddy version:
Caddy v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
Docker
a. System environment:
Ubuntu 22.04.4 LTS
Docker version 27.1.2, build d01f264
b. Command:
c. Service/unit/compose file:
services:
caddy:
image: caddy:alpine
restart: unless-stopped
ports:
- 10.1.0.172:80:80
- 10.1.0.172:81:81
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
d. My complete Caddy config:
{
auto_https off
}
http://10.1.0.172:81 {
redir http://10.1.1.1:80
}
http://10.1.0.172:80 {
handle /* {
reverse_proxy http://10.1.1.1:80 {
header_up Host {header.X-Forwarded-Host}
}
}
handle_errors {
respond "{err.status_code} {err.status_text}"
}
}