简体   繁体   中英

Traefik: Access service via local IP address as well as externally (https)?

I managed to setup a reverse proxy with my domain ( https://MY-DOMAIN.COM ), and I think I read that it's also possible to access the service on my local network ( http://192.168.0.5:8123 or http://my-server.local:8123 ), not just externally via https.

Anyone know if this is true, and if so how I'd set that up?

Here's my docker-compose.yml code:

version: '3'

networks:
  proxy:
    external: true

services:
  reverse-proxy:
    container_name: ReverseProxy
    image: traefik
    restart: always
    command: --web --docker
    ports:
      - 8080:8080
      - 80:80
      - 443:443
    networks:
      - proxy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ~/docker/traefik/traefik.toml:/traefik.toml
      - ~/docker/traefik/acme.json:/acme.json

  homeassistant:
    image: homeassistant/home-assistant
    container_name: home-assistant
    restart: unless-stopped
    networks:
      - proxy
    expose:
      - 8123
    volumes:
     - ~/docker/homeassistant:/config
     - /etc/localtime:/etc/localtime:ro
    labels:
      - "traefik.backend=home-assistant"
      - "traefik.docker.network=proxy"
      - "traefik.frontend.rule=Host:MY-DOMAIN.COM"
      - "traefik.enable=true"
      - "traefik.port=8123"
      - "traefik.default.protocol=http"


And here's my traefik.toml code:

debug = false

logLevel = "ERROR"
defaultEntryPoints = ["https","http"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
  [entryPoints.https.tls]

[retry]

[web]
address = ":8080"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "MY-DOMAIN.COM"
watch = true
exposedbydefault = false

[acme]
email = "MY-EMAIL-ADDRESS"
storage = "acme.json"
entryPoint = "https"
OnHostRule = true
[acme.httpChallenge]
entryPoint = "http"

[[acme.domains]]
  main = "MY-DOMAIN.COM"

On your homeassistant docker-compose config change the following to allow your host to map 8123 to the container.

from:

expose:
  - 8123

to:

ports:
  - "8123:8123"

source: What is the difference between docker-compose ports vs expose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM