alexta69 / metube

Self-hosted YouTube downloader (web UI for youtube-dl / yt-dlp)
GNU Affero General Public License v3.0
3.95k stars 259 forks source link

Caddy reverse proxy redirect loop #460

Closed proess880 closed 5 days ago

proess880 commented 1 week ago

I want to deply metub behind Caddy (docker) as a reverse proxy. However i am unable to get it redirected properly.

docker-compose.yml

services:
  metube:
    image: ghcr.io/alexta69/metube
    container_name: metube
    restart: unless-stopped
    networks:
      - proxy
    volumes:
      - /media/share/Downloads:/downloads
      - ./data:/app/data
    environment:
      DOWNLOAD_DIR: /downloads
      STATE_DIR: /app/data/state
      TEMP_DIR: /app/data/temp
      URL_PREFIX: /metube

networks:
  proxy:
    external: true

Caddyfile

https://services.mydomain.com {
    handle_path /metube/* {
        uri strip_prefix /metube  -> Also tried removing this line since **handle_path** does the same
        reverse_proxy http://metube:8081
    }
}

but i get an infinite redirect loop

grafik

And the logs of the container there are errors

INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:37:47 +0000] "UNKNOWN / HTTP/1.0" 400 225 "-" "-"
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:

    b'\x16\x03\x01\x01\x05\x01'
      ^
INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:38:04 +0000] "UNKNOWN / HTTP/1.0" 400 225 "-" "-"
ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:

    b'\x16\x03\x01\x01\x05\x01'
      ^
INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:38:07 +0000] "UNKNOWN / HTTP/1.0" 400 225 "-" "-"
INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:38:15 +0000] "GET / HTTP/1.1" 302 185 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"
INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:38:15 +0000] "GET / HTTP/1.1" 302 185 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"
INFO:aiohttp.access:172.26.0.2 [23/Jun/2024:05:38:15 +0000] "GET / HTTP/1.1" 302 185 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0"
PikuZheng commented 1 week ago

URL_PREFIX: /metube handle_path /metube/* { ~uri strip_prefix /metube~

or

URL_PREFIX: / handle_path /metube/* { uri strip_prefix /metube

proess880 commented 5 days ago

it only worked after setting URL_PREFIX: / and accessing with https://services.mydomain.com/metube/ (Notice the trailing slash is important) Which kinda makes URL_PREFIX obsolete

Caddyfile

https://services.mydomain.com {
    handle_path /metube/* {
        reverse_proxy http://metube:8081
    }
}