Can not redirect to service properly

1. The problem I’m having:

I had installed the Jellyfin and also Caddy as docker containers:

The Caddy docker-compose file:

version: '3.9'

services:
  caddy:
    image: caddy:latest
    container_name: caddy-container
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /share/homes/<USER>/CaddyConf/Caddyfile:/etc/caddy/Caddyfile
      - /share/homes/<USER>/ssl_certs:/ssl_certs
      - caddy_data:/data
      - caddy_config:/config
    stdin_open: true
    tty: true

volumes:
  caddy_data:
  caddy_config:

The jellyfin docker command:

  docker run -d \
  --name jellyfin \
  -v /share/homes/<USER>/jellyfin_config/config:/config \
  -v /share/homes/<USER>/jellyfin_config/cache:/cache \
  -v /share/Movies:/media \
  --network=host \
  jellyfin/jellyfin:latest

Both of them are running under a QNAP NAS.

I register my DDNS under dynu.com and my domain lets say is <MY_DOMAIN>.ooguy.com.

This is the configuration for the Caddy:

<MY_DOMAIN>.ooguy.com {
    reverse_proxy /* 192.168.0.98:8085
    reverse_proxy /jellyfin/* 192.168.0.98:8096
    tls /ssl_certs/<MY_DOMAIN>.ooguy.com_2023.crt /ssl_certs/myserver.key
}

2. Error messages and/or full log output:

When I am trying to access <MY_DOMAIN>.ooguy.com:443/jellyfin/ instead of been redirected to the 192.168.0.98:8096 on which my service is running I will get a white page and nothing is going to load.

2023/12/02 00:42:17.932 INFO    using provided configuration    {"config_file": "/etc/caddy/Caddyfile", "config_adapter": "caddyfile"}
2023/12/02 00:42:17.934 WARN    Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies    {"adapter": "caddyfile", "file": "/etc/caddy/Caddyfile", "line": 1}
2023/12/02 00:42:17.936 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/12/02 00:42:17.939 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0005d4100"}
2023/12/02 00:42:27.948 WARN    tls     stapling OCSP   {"error": "no OCSP stapling for [<MY_DOMAIN>.ooguy.com www.<MY_DOMAIN>.ooguy.com]: getting issuer certificate: Get \"http://crt.sectigo.com/SectigoRSADomainValidationSecureServerCA.crt\": dial tcp: lookup crt.sectigo.com on 127.0.0.11:53: read udp 127.0.0.1:50690->127.0.0.11:53: i/o timeout"}
2023/12/02 00:42:27.949 INFO    http.auto_https skipping automatic certificate management because one or more matching certificates are already loaded  {"domain": "<MY_DOMAIN>.ooguy.com", "server_name": "srv0"}
2023/12/02 00:42:27.949 INFO    http.auto_https enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2023/12/02 00:42:27.949 INFO    http    enabling HTTP/3 listener        {"addr": ":443"}
2023/12/02 00:42:27.949 INFO    tls     cleaning storage unit   {"description": "FileStorage:/data/caddy"}
2023/12/02 00:42:27.949 INFO    tls     finished cleaning storage units
2023/12/02 00:42:27.949 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/12/02 00:42:27.949 INFO    http.log        server running  {"name": "remaining_auto_https_redirects", "protocols": ["h1", "h2", "h3"]}
2023/12/02 00:42:27.949 INFO    autosaved config (load with --resume flag)      {"file": "/config/caddy/autosave.json"}
2023/12/02 00:42:27.949 INFO    serving initial configuration

3. Caddy version:

3.18.5

4. How I installed and ran Caddy:

via this docker compose file:

version: '3.9'

services:
  caddy:
    image: caddy:latest
    container_name: caddy-container
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /share/homes/<USER>/CaddyConf/Caddyfile:/etc/caddy/Caddyfile
      - /share/homes/<USER>/ssl_certs:/ssl_certs
      - caddy_data:/data
      - caddy_config:/config
    stdin_open: true
    tty: true

volumes:
  caddy_data:
  caddy_config:

a. System environment:

QNAP NAS

Why are you running Jellyfin in host mode? Why not put it in your docker-compose.yml alongside Caddy? Then proxying from Caddy to Jellyfin will be easier, since you can just use the container name.

Otherwise, you can use host.docker.internal to proxy to the host machine (google it).

I’ve tired also this option but the output is the same. The problem is not that the network is host or not, is that the redirect is not happening as it should (with or without ‘host’)

You haven’t shown evidence of a problem. Make a request with curl -v to show the behaviour you’re seeing.

I’m sorry because I’ve responded so late. I found the problem interesting enough that it has nothing to do with the caddy itself.

The problem was solved after I set the Base URL of Jellyfin to be /jellyfin. And not all the redirects are working fine.

But what I don’t understand is that… based on the configuration of the Caddy

    reverse_proxy /jellyfin/* 192.168.0.98:8096

This should redirect all the calls from something like DOMAIN:PORT/jellyfin/ to 192.168.0.98:8096/

But in reality, this is not working as I expected because I have to add that Base URL, which means I will have to redirect this DOMAIN:PORT/jellyfin/ to this 192.168.0.98:8096/jellyfin/ and then is going to work as properly.

No, you used a path matcher, which does not manipulate the URL.

If you wanted to strip the path prefix from the request then you’d need to use handle_path.

See this article which explains some concepts:

Aaaa now I get it, this makes a lot more sense now :smiley: . Thanks a lot for bringing it up to me :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.