Traefik 2 on Synology unable to connect to services on the host network

Hi, I'm hoping someone with a lot more expertise than myself can help, Ive been stuck on this for the last 2 weeks. I feel like im getting close to getting this working and just need to get over this last hurdle.

I work as a developer and we have started using docker in work and so am comfortable with docker and programing in general however networking and certificates are all very new to me. I will try and explain the best i can but please feel free to correct all my mistakes/ misconceptions as thats the only way i will get to learn. I wanted to impove my skills in these areas hence setting all this up in my home network so what to learn and understand what im doing rather than just get it working blindly if that makes anysense.
Anyway enough of the rambling here the details:

What ive trying to achieve:
Route traffic from over https (443) > Home Assistant > Synology DSM home page.

Synology IP > (changed built-in ngix poxy ports 80 >81 &443> 444)
Home Assistant > Installed in docker, uses host network exposing port 8123
DSM > uses port 5000
Domain and DNS setup in cloudflare
Create A and CName records with proxied status proxied (have also tryed DNS only)
and have set SSL/TLS to Full
traefik installed in docker on Synology
taefik docker network (gw - bridge mode
router port forward enabled 443 >
Using yaml file to configure Home Assistant Service Rule

Whats working
Staring with the positives....
Any container i build with docker compose works (if on same traefik network)
Any services not using docker that are not on the same ip as the docker host

The Problem
When i try an access or i get error 504 gateway times out.
I know i must be close as if i change the forwarding address to say my router IP it works.
As a test (as i would do this via docker compose than a file) I have also tried to point at another container i have installed that exposes port 8989 and if try pointing at it doesnt work ... however if i change this to point at the dockers container IP ( it works.
So basically it appears any port that is on the Synology / Docker host IP ( doesnt seem to work.
If tried replacing the docker host with and and same result
I sure there is something silly im overlooking here around the routing or maybe around the fact its gong from https externaly to http internally so could it be something with certificate termination ??? forgive me as my knowlege on certs / tls is very very limited and to be honest im suprised i have gotten this far.
My docker compose and yaml config fies are attached ... in there i have setup google oauth and this appears to be working, i have also tried without to try and reduce complication but didnt make a difference.

I've tried following the docs on traefik, numerous google serarchs and forum posts and tried so many things that would make this long post even longer. (Happy to retry all test again though)
It seems like it should work and looking at so many examples i dont see what i have done that is different to others that have it working.

Any help or pointers would be greatly apreciated or if anyone has some good reading material on certs, and reverse proxies in gerneal that would also be welcomed.


Docker Compose

version: "2.1"

      name: traefik_network
    driver: bridge

    container_name: "traefik"
    image: "traefik:v2.2"
    restart: "always"
    mem_swappiness: -1
      - "no-new-privileges:true"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"    # <--- Allows acces to docker to talk to another containers
      - "/volume2/Docker/Traefik/certs:/certs"            # <--- Location for the cerrs
      - "/volume2/Docker/Traefik/logs:/logs"              # <--- Location of the Logs
      - "/volume2/Docker/Traefik/rules:/rules"            # <--- Location of the dynamic Rules
      - "80:80"        # <--- Web
      - "443:443"      # <--- WebSecure
      - "8080:8080"    # <--- Traefik Dashboard
      - "CF_API_EMAIL=xxx"                   #  <--- Cloudflare username
      - "CF_API_KEY=xxx"    #  <--- Cloudflare Api key
    ## Logs
      - "--log=true"                       #  <--- Enabled logs
      - "--log.level=DEBUG"                #  <--- Log values: DEBUG, INFO, WARN, ERROR, FATAL, PANIC (Default: error)
      - "--log.format=json"                #  <--- Log format
      - "--log.filePath=/logs/traefik.log" #  <--- Location of the Logs

    ## Access Logs
      - "--accessLog=true "                             # <--- enable access logs
      - "--accessLog.filePath=/logs/traefik_access.log" # <--- Location of Log files
      - "--accessLog.bufferingSize=100"                 # <--- Configuring a buffer of 100 lines
      - "--accessLog.filters.statusCodes=400-49"        # <--- Only get codes in the 400 range

    ## API
      - "--api.insecure=true"
      - "--api.dashboard=true"
      - "--api=true"

    ## Entry Points - listen for incoming traffic (ports, ...)
      - "--entrypoints.websecure.address=:443"        # <--- Listen on port 443 for incoming requests. Friendly name websecure has been given
      # - "--entrypoints.traefik.address=:8080"
      # - "--entrypoints.web.address=:80"

      #### Add cloudflare as default certresolver for all services. Also enables TLS and no need to specify on individual services.
      - "--entrypoints.websecure.http.tls.certresolver=cloudflare"
      - "[0]"
      - "[0].sans=*"
      - "--entrypoints.websecure.forwardedHeaders.trustedIPs=,,,,,,,,,,,,,"

    ## Providers - discover the services that live on your infrastructure (their IP, health, ...)
      - ""
      - "--providers.docker=true"                     #  <--- Enable Traefik on Docker
      - "--providers.docker.exposedbydefault=false"   #  <--- Do not expose all Docker Containers by default
      - ""           #  <--- Folder to store rules in
      - ""                 #  <--- Only works on top level files in the rules folder

    ## DNS Challenge Challenge
      #### (cloudflare can be anything you want, called it cloudfare to give it some meaning)
      - "--certificatesresolvers.cloudflare.acme.dnschallenge=true"                   #  <--- What type of Cert Challenge to LetEncrypt ... DNS is used not HTTP or TLS
      - "--certificatesresolvers.cloudflare.acme.dnschallenge.provider=cloudflare"    #  <--- Where is the DNS Hosted (Used Cloudflare in this case)
      - ""                          #  <--- Username for Cloudfare
      - ""            #  <--- Location of to Store the Cert

    ## Enable Traefik
      - "traefik.enable=true"    #  <--- Enable traefik to manage this container
    ## Router
      - "traefik.http.routers.api.rule=Host(``)"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.middlewares=google_oauth@file"

    container_name: google_oauth
    image: thomseddon/traefik-forward-auth:latest
    restart: always
    mem_swappiness: -1
      - no-new-privileges:true
      - CLIENT_ID=xxxx
      - CLIENT_SECRET=xxx
      - SECRET=xxx
      - INSECURE_COOKIE=false
      - URL_PATH=/_oauth
      - WHITELIST=xxx
      - LOG_LEVEL=warn
      - LOG_FORMAT=text
      - LIFETIME=2592000 # 30 days
      - DEFAULT_ACTION=auth
      - DEFAULT_PROVIDER=google
      - "traefik.enable=true"

      ## HTTP Routers
      - "traefik.http.routers.oauth_router.entrypoints=websecure"
      - "traefik.http.routers.oauth_router.rule=Host(``)"
      - "traefik.http.routers.oauth_router.service=oauth_service"

      ## Middlewares
      - "traefik.http.routers.oauth_router.middlewares=google_oauth@file"

      ## HTTP Services
      - ""

    image: "containous/whoami"
    container_name: "simple-service"
      - "traefik.enable=true" #  <--- Enable traefik to manage this container

      # Define the routers (frontend) - Match the to the container name for easy management
      - "traefik.http.routers.whoami_router.rule=Host(``) && PathPrefix(`/whoami`)"  #  <--- What rule to match entry point too.
      - "traefik.http.routers.whoami_router.entrypoints=websecure"                                       #  <--- What entry point to check

      # Middlewares
      - "traefik.http.routers.whoami_router.middlewares=google_oauth@file"    #  <--- Call middleware authenitication (google oAuth)

      # Define the Services (backend)
      - ""   #  <--- Where to direct the service too

dynamic config file .yaml

      rule: "Host(``)"
        - "websecure"
        # - google_oauth
        # - chain-no-auth
      service: "homeassistant_service"
        passHostHeader: true
         # - url: "" # Home assistant home page (not working)
         # - url: "" # Synology DSM home page  (not working)
         # - url: ""       # routers home page (works)
         # - url: "" # sonarr internal docker network (works)
          - url: ""       # sonarr docker host  (not working)

Thanks for the information sharing

i have it configured as followed:

        - https
      service: service-hass
      rule: Host("")
        - "hsts"
      tls: {}

          - url:
        passHostHeader: true
        passTLSCert: true

i have used the following guide:

Thanks for the pointer.
I double checked my config file and made a few tweaks for replicate yours and im still getting 504 Error - gateway time-out.
I'll take a look at the link you provided now and do a bit more reading.

I think there is something on my synology NAS that is blocking or conflicting with it, that is causing issues.
its weird as i can get to from any browser on the LAN. traefik just wont redirect to it for some reason.

are you using the from inside your network?
then it could be that your router is not supporting nat loopback.

ah yes i am ... let me flip to 4g and test

tried that and still no joys. I read that article and cant see anything obvious that im doing wrong. Im in the middle of redoing the whole compose file at moment and going to more a file based approach like the article. Not that i think it will make a difference but i just want to follow that article exactly at the moment, then if it works i can reverse engineer it back to my approach to see where i went wrong :stuck_out_tongue:

thanks so much for your input and feedback, its much apreciated as i dont really know what im doing haha

The only other think i can think about is the firewall on your synology.

Are Home Assistant and traefik on the same nas? Maybe you can try

yes both traefik and home assistant are installed on the same nas on the same docker host.

I've tried using and (not sure the difference between the 2 to be honest) and still had the same issue. I'll try again now though as i have made some changes so it might now work.

i've had a look around on synology front and cant see anything obvious there. Havent got firewall set as far as i can tell.

i did try and replicating the article but failed massively and kept getting ssl handshake issues, so have reverted back to original for now, as that seemed in a more working state as i couldnt even access the dashboard, so clearly messed something up there... I will attempt again either later this evening or tomorrow.
the only thing i can really see that is massively different is the tls file. Is this needed?

      minVersion: VersionTLS13
        - TLS_AES_128_GCM_SHA256
        - TLS_AES_256_GCM_SHA384
        - TLS_CHACHA20_POLY1305_SHA256
      sniStrict: true
      minVersion: VersionTLS12
      sniStrict: true

Following the article i cant see where this file is called? so no idea where this would fit into my current setup... the rules folder?
In the hass file it sets tls to null by the looks of it so im really confussed by the point of the above file

  tls: {}

I am leaning towards there being something on the synology side of things, blocking or conflicting with what im trying to do

ok think you might be onto something with firewall or something blocking it ... i logged into the console for the traefik container and tried to ping (nas) and i couldnt.
I can ping the router and also another machine on my network just not the nas/docker host network ... thing is my networking skill are terrible as are my linux skills so not sure where to go from here.
i did an iptables from the docker host and cant see anything blocking or denying and iptables is not installed on traefik so it cant be that which is blocking the connection. any ideas?

ok i've resolved the issue.
@jonathanmos massive thankyou for pointing me in the right direction

So i had to reference the gateway of the network that traefik container lived on. So for me this was
That address is actually the same as my docker host,
So putting in in my yaml file worked.
Below is my config for homeassistant should anybody be interested.

        - websecure
      service: service-hass
      rule: Host("")

          - url:
        passHostHeader: true

No problem glad you got it working!