Search code examples
dockerhttpsportcloudflare

How to redirect subdomain to port (docker)


I have a docker container running vaultwarden and another one running a dashboard. How to I get vault.example.com to redirect to serverIP:8080, and dash.example.com to serverIP:9090? I use cloudflare, but tunnels have proved unsuccessful


Solution

  • This config of a tunnel would do the work:

    tunnel: the_ID_of_the_tunnel
    credentials-file: /root/.cloudflared/the_ID_of_the_tunnel.json
    
    ingress:
      - hostname: vault.example.com
        service: http://serverIP:8080
      - hostname: dash.example.com
        service: http://serverIP:9090
      - service: http_status:404
    

    If you want to add more traffic rules, check this doc: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local/local-management/ingress/

    If you want a step-by-step guide on how to set-up the tunnel on a container, you can watch this video: https://youtu.be/GCQHulz5fjY

    Bear in mind that the tunnel (if ran as a container) has to run on the host network to be reachable. Make sure the ports you're exposing, i.e. 8080 and 9090 are not taken by any other service on the host. If they are, just remap and expose a different port.