Having trouble taking a location and appending it to the reverse proxy

1. Caddy version:

Caddy Version: v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=
I am using docker-compose

2. How I installed, and run Caddy:

I installed via docker-compose.

a. System environment:

Ubuntu 20.04.5 LTS, systemd, Dockercat

b. Command:

docker-compose up -d

c. Service/unit/compose file:

version: '3'

services:
    caddy:
        image: caddy:latest
        container_name: caddy
        restart: unless-stopped
        ports:
            - 443:443
        volumes:
            - ./Caddyfile:/etc/caddy/Caddyfile
            - ./site:/srv
            - ./caddy_data:/data:rw
            - ./caddy_config:/config:rw


    reddfeed:
        build: Reddfeed
        container_name: reddfeed
        image: reddfeed:latest
        restart: unless-stopped


    peertube:
        image: chocobozzz/peertube:production-bullseye
        container_name: peertube
        networks:
          default:
            ipv4_address: 172.18.0.42
        env_file:
          - ./Peertube/.env
        ports:
          - 1935:1935
          - 9000:9000
        volumes:
          - assets:/app/client/dist
          - ./Peertube/docker-volume/data:/data
          - ./Peertube/docker-volume/config:/config
        depends_on:
          - postgres
          - redis
          - postfix
        restart: unless-stopped


    postgres:
        image: postgres:13-alpine
        container_name: peertube-postgres
        env_file:
          - ./Peertube/.env
        volumes:
          - ./Peertube/docker-volume/db:/var/lib/postgresql/data
        restart: unless-stopped


    redis:
        image: redis:6-alpine
        container_name: peertube-redis
        volumes:
          - ./Peertube/docker-volume/redis:/data
        restart: unless-stopped


    postfix:
        image: mwader/postfix-relay
        container_name: peertube-postfix
        env_file:
          - ./Peertube/.env
        volumes:
          - ./Peertube/docker-volume/opendkim/keys:/etc/opendkim/keys
        restart: unless-stopped

networks:
  default:
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16

volumes:
  assets:

d. My complete Caddy config:

synhang.ddns.net {
    tls MYEMAIL@protonmail.com
    file_server
    reverse_proxy /posts* reddfeed:5000{uri}
    reverse_proxy /sub/* reddfeed:5000{uri}
    reverse_proxy /watch* peertube:9000
}

3. The problem I’m having:

My intention is to have ‘/’ go to a static webpage (which it does fine). If a user types this location: https:// synhang. ddns .net/posts it should reverse_proxy to the reddfeed container which is a flask app listening on 0.0.0.0:5000. If the user types the /sub/ URI they need an additional section behind it like so: https://synhang.ddns.net/sub/arduino. Finally, if a user types this URI: https:// synhang .ddns .net/watch it should redirect to my peertube instance which is listening on port 9000.

4. Error messages and/or full log output:

5. What I already tried:

When loading the local IP in a browser to access the resources directly. I.e. http://192.168.0.23:5000/posts or http://192.168.0.23:5000/sub/arduino I can access the resources just fine. Likewise if I load http://192.168.0.23:9000 I get the peertube instance. But if I try to access it via the domain. I get these errors:

For the :5000 URIs I get a 502 bad gateway error. And for the /watch endpoint I get

Loading module from “https://synhang.ddns.net/client/en-US/runtime.ce410da37895951f.js” was blocked because of a disallowed MIME type (“”).

and errors such as:

GET https://synhang.ddns.net/client/en-US/styles.89b7ff258a4af6c2.css

Which is a 404
There are many such errors
I know with Nginx I can have and include mime.types; directive to catch most mimes but how do I do this with caddy.

But the 502 and 404 errors are not occurring when running from within the LAN

6. Links to relevant resources:

Remove {uri} from your proxy address. The reverse_proxy takes a dial address, not a URL.

You mean “proxy”, not “redirect”. Those are separate and distinct concepts in HTTP.

A redirect is a special type of HTTP response which has a Location header which tells the client to try again at a different URL.

I removed {uri} from both reverse_proxy directives and it is still giving the same error. I need the reverse_proxy to append /posts to reddfeed:5000 because there is no ‘/’ location on that container

Path matchers in Caddy don’t strip the matched prefix before handling. So you don’t need to add anything to the URL, because it’ll remain the same as the incoming request.

Enable the debug global option. What’s in your Caddy logs?

Ok, here is what I think the root of the issue is:

"http.log.error","msg":"dial reddfeed:5000: unknown network reddfeed:5000"

It isn’t resolving the container name reddfeed. But this is the service name so it should resolve through docker?

I wonder why it thinks reddfeed is a network and not a host.

What’s your config at this point?

Please provide all current info when you make a comment, we can’t make assumptions about where you’re at.

This is my Caddyfile:

{
        debug
}

synhang.ddns.net {
    tls my_email@protonmail.com
    file_server
    reverse_proxy /posts reddfeed:5000

    reverse_proxy /sub/* reddfeed:5000

    reverse_proxy /watch* peertube:9000
}

Are you sure you reloaded your config after removing {uri}?

“Unknown network” is usually when there’s a / in the dial address, because the network part is something like tcp/ as a prefix to the dial address. See Conventions — Caddy Documentation.

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