almeidapaulopt / tsdproxy

Tailscale Docker Proxy
MIT License
438 stars 16 forks source link

Container with internal port of 80 causes infinite redirection #46

Closed wolffshots closed 13 hours ago

wolffshots commented 2 weeks ago

When using a container with an internal port of 80 it causes the too many redirects (HTTP/1.1 308 Permanent Redirect).

Encountered when using tsdproxy with Audiobookshelf which by default uses 13378:80 as the ports but luckily I could change the internal port with the PORT environment variable (as per https://github.com/advplyr/audiobookshelf/issues/2041) which sorted out the issue for me but for some containers it might not be possible to change the port like that.

I confirmed this behaviour with some other containers that allowed me to change the internal port to 80

theshoehorn commented 2 weeks ago

I've noticed similar things. Running a reverse proxy for my personal domain on the same docker instance. When enabling a container with internal port 80, TsDProxy is serving my reverse proxy container instead, which is listening on 80 both internal and external.

glassejt commented 1 week ago

Of course the app I tried testing the proxy with was audiobookshelf. Thanks for the post! I couldn't figure out what was going wrong.

almeidapaulopt commented 6 days ago

When using a container with an internal port of 80 it causes the too many redirects (HTTP/1.1 308 Permanent Redirect).

Encountered when using tsdproxy with Audiobookshelf which by default uses 13378:80 as the ports but luckily I could change the internal port with the PORT environment variable (as per advplyr/audiobookshelf#2041) which sorted out the issue for me but for some containers it might not be possible to change the port like that.

I confirmed this behaviour with some other containers that allowed me to change the internal port to 80

can you give more details? in the environment I'm using all containers internal port is 80 without that behavior. I've tested with 1 nginx (80) in several type os network. network_mode:host, in the same network and in other network.

wolffshots commented 6 days ago

Here's my tsdproxy stack:

services:
  tailscale-docker-proxy:
    image: almeidapaulopt/tsdproxy:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./tsdproxy/data:/data
    restart: unless-stopped
    environment:
      - TSDPROXY_AUTHKEY=${TSDPROXY_AUTHKEY}
      - TSDPROXY_HOSTNAME=192.168.0.124
      - DOCKER_HOST=unix:///var/run/docker.sock
      - TSDPROXY_LOG_LEVEL=info
networks: {}

and here is my what my Audiobookshelf looks like when I was getting the redirects:

services:
  audiobookshelf:
    image: ghcr.io/advplyr/audiobookshelf:latest
    ports:
      - 13378:80
    volumes:
      - ./audiobooks:/audiobooks
      - ./config:/config
      - ./metadata:/metadata
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    labels:
      tsdproxy.enable: "true"
      tsdproxy.name: audiobookshelf
      tsdproxy.container_port: 80
      tsdproxy.authkey: ${TSDPROXY_AUTHKEY}

and here is what I did to work around the issue:

services:
  audiobookshelf:
    image: ghcr.io/advplyr/audiobookshelf:latest
    ports:
-    - 13378:80
+    - 13378:13378 # originally 13378:80
    volumes:
      - ./audiobooks:/audiobooks
      - ./config:/config
      - ./metadata:/metadata
      - /etc/localtime:/etc/localtime:ro
+   environment:
+     - PORT=13378
    restart: unless-stopped
    labels:
      tsdproxy.enable: "true"
      tsdproxy.name: audiobookshelf
-     tsdproxy.container_port: 80
+     tsdproxy.container_port: 13378
      tsdproxy.authkey: ${TSDPROXY_AUTHKEY}

but now on trying again it seems this also works:

services:
  audiobookshelf:
    image: ghcr.io/advplyr/audiobookshelf:latest
    ports:
     - 13378:80
    volumes:
      - ./audiobooks:/audiobooks
      - ./config:/config
      - ./metadata:/metadata
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    labels:
      tsdproxy.enable: "true"
      tsdproxy.name: audiobookshelf
-     tsdproxy.container_port: 80
+     tsdproxy.container_port: 13378
      tsdproxy.authkey: ${TSDPROXY_AUTHKEY}

But from this note in the docs it should be the internal port so this config shouldn't work like this, right?

To test between each change I was using httpie rather than a browser to hopefully not have any browser cache funny business:

http --follow --all https://audiobookshelf.<funny>-<name>.ts.net
almeidapaulopt commented 1 day ago

please confirm if it's fixed in v1.0.0

wolffshots commented 13 hours ago

It is indeed sorted in v1.0.0, thanks!