louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
55.82k stars 5.02k forks source link

Uptime Kuma: 526 Error Code on Redirect When Using Custom HTTP Headers with Traefik Reverse Proxy #4975

Open zylxpl opened 1 month ago

zylxpl commented 1 month ago

πŸ“‘ I have found these related issues/pull requests

NA

πŸ›‘οΈ Security Policy

Description

I am trying to monitor several services behind a Traefik reverse proxy using Uptime Kuma. Both Traefik and Uptime Kuma are on the same Docker network, and I am using Docker's DNS resolution to connect to the Traefik container by specifying its Docker DNS name (https://traefik/) in the URL field.

To ensure Traefik correctly handles requests to specific services, I am setting the HTTP header Host with the appropriate domain (e.g., whoami.example.com). Traefik also requires the correct Server Name Indication (SNI) or a matching domain to respond with the correct certificate. This setup works for most services. However, I encounter an issue with services that respond with a redirect. For these services, Uptime Kuma returns a 526 error code.

When manually checking these services, they work as expected. Additionally, if I specify the final path after redirects in the URL, it works correctly. This leads me to believe that Uptime Kuma might not be handling HTTP headers properly during redirects.

πŸ‘Ÿ Reproduction steps

  1. Set Up Docker Network:

    Ensure that both Traefik and Uptime Kuma are on the same Docker network.

  2. Configure Traefik:

    Set up Traefik with services that include redirects, e.g. Prometheus Ensure Traefik is configured to handle ssl requests.

  3. Set Up Uptime Kuma:

    Deploy Uptime Kuma on the same Docker network. Add a new monitor in Uptime Kuma. In the URL field, specify the Docker DNS name of the Traefik container (e.g., https://traefik).

  4. Set HTTP Header in Uptime Kuma:

    Set the HTTP header Host to the appropriate domain for the service (e.g., prometheus.example.com).

  5. Test Service with Redirects:

    Ensure the service behind Traefik responds with a redirect. Observe that Uptime Kuma returns a 526 error code.

  6. Manual Check:

    Manually access the service URL with the same Host header and note that it works correctly. Specify the final path after redirects in Uptime Kuma's URL field (e.g. /graph) and observe that it works correctly.

πŸ‘€ Expected behavior

πŸ˜“ Actual Behavior

🐻 Uptime-Kuma Version

1.23.13

πŸ’» Operating System and Arch

Ubuntu 20.04 aarch64

🌐 Browser

Firefox

πŸ–₯️ Deployment Environment

πŸ“ Relevant log output

No response

CommanderStorm commented 1 month ago

What kind of a redirect+method are you using? https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections

zylxpl commented 1 month ago

In my case all of them are 302 Found redirections:

< HTTP/2 302 
< alt-svc: h3=":443"; ma=2592000
< content-type: text/html; charset=utf-8
< date: Tue, 30 Jul 2024 22:17:06 GMT
< location: /graph
< content-length: 29