Traefik无法路由到某些容器的适当后端

时间:2019-02-19 13:59:12

标签: traefik

我的某些前端未正确路由到后端。 我有2个容器: -搬运工; -家庭助理; Portainer可以正常工作,但是homeassantant无法正确路由到后端。

我的docker-compose:

version: "3.6"
services:

  portainer:
    image: portainer/portainer
    container_name: portainer
    domainname: ${DOMAINNAME}
    hostname: portainer
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ${USERDIR}/dockerha/uavportainer/data:/data
      - ${USERDIR}/dockerha/shared:/shared
    environment:
      - TZ=${TZ}
    networks:
      - ${NETWORK_NAME}
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${DOMAINNAME}; PathPrefixStrip: /portainer"
      - "traefik.backend=portainer"
      - "traefik.port=9000"
      - "traefik.frontend.entryPoints=http"

  homeassistant:
    image: homeassistant/home-assistant
    container_name: homeassistant
    domainname: ${DOMAINNAME}
    hostname: homeassistant
    volumes:
      - ${USERDIR}/dockerha/uavha:/config
      - /etc/localtime:/etc/localtime:ro
      - ${USERDIR}/dockerha/shared:/shared
    ports:
      - "8123:8123"
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    networks:
      - ${NETWORK_NAME}
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${DOMAINNAME};PathPrefixStrip:/hass"
      - "traefik.backend=hass"
      - "traefik.port=8123"
      - "traefik.frontend.entryPoints=http"

toml文件:

[accessLog]
  filepath = "/etc/traefik/access.log"
  format = "json"

debug = true

logLevel = "DEBUG" #"ERROR" #DEBUG, INFO, WARN, ERROR, FATAL, PANIC

#InsecureSkipVerify = true
defaultEntryPoints = ["http", "https"]

# WEB interface of Traefik - it will show web page with overview of frontend an$
[api]
  entryPoint = "traefik"
  dashboard = true
  address = ":8080"
#  usersFile = "/shared/.htpasswd"

# Force HTTPS
[entryPoints]
  [entryPoints.http]
  address = ":80"


[file]
watch = true

[docker]
Endpoint = "unix:///var/run/docker.sock"
Domain = "192.168.56.102"
watch = true
SwarmMode = true
network = "uavhanet"
ExposedRyDefault = false

以下是2种不同的访问日志:

工作一个:

{
  "BackendAddr": "10.0.14.11:9000",
  "BackendName": "backend-portainer",
  "BackendURL": {
    "Scheme": "http",
    "Opaque": "",
    "User": null,
    "Host": "10.0.14.11:9000",
    "Path": "",
    "RawPath": "",
    "ForceQuery": false,
    "RawQuery": "",
    "Fragment": ""
  },
  "ClientAddr": "192.168.56.1:58089",
  "ClientHost": "192.168.56.1",
  "ClientPort": "58089",
  "ClientUsername": "-",
  "DownstreamContentSize": 3,
  "DownstreamStatus": 200,
  "DownstreamStatusLine": "200 OK",
  "Duration": 3927995,
  "FrontendName": "Host-192-168-56-102-PathPrefixStrip-portainer-4",
  "OriginContentSize": 3,
  "OriginDuration": 3468375,
  "OriginStatus": 200,
  "OriginStatusLine": "200 OK",
  "Overhead": 459620,
  "RequestAddr": "192.168.56.102",
  "RequestContentSize": 0,
  "RequestCount": 63,
  "RequestHost": "192.168.56.102",
  "RequestLine": "GET /portainer/api/teams HTTP/1.1",
  "RequestMethod": "GET",
  "RequestPath": "/portainer/api/teams",
  "RequestPort": "-",
  "RequestProtocol": "HTTP/1.1",
  "RetryAttempts": 0,
  "StartLocal": "2019-02-19T12:45:44.966258565Z",
  "StartUTC": "2019-02-19T12:45:44.966258565Z",
  "downstream_Content-Length": "3",
  "downstream_Content-Type": "application/json",
  "downstream_Date": "Tue, 19 Feb 2019 12:45:44 GMT",
  "downstream_X-Content-Type-Options": "nosniff",
  "downstream_X-Xss-Protection": "1; mode=block",
  "level": "info",
  "msg": "",
  "origin_Content-Length": "3",
  "origin_Content-Type": "application/json",
  "origin_Date": "Tue, 19 Feb 2019 12:45:44 GMT",
  "origin_X-Content-Type-Options": "nosniff",
  "origin_X-Xss-Protection": "1; mode=block",
  "request_Accept": "application/json, text/plain, */*",
  "request_Accept-Encoding": "gzip, deflate",
  "request_Accept-Language": "en-US,en;q=0.9",
  "request_Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInJvbGUiOjEsImV4cCI6MTU1MDU5ODIzMn0.nOzaZYo7gu3An_nHZMpCqPnQ0XNFEvEfrivZ40RumUI",
  "request_Connection": "keep-alive",
  "request_Cookie": "_ga=GA1.1.364506726.1550080124; _gid=GA1.1.376969405.1550080124; portainer.UI_STATE=%7B%22dismissedInfoPanels%22%3A%7B%7D%2C%22dismissedInfoHash%22%3A%22y%2BAiiJOM%2Feqr4gyAl6VKBw%3D%3D%22%7D; pma_lang=en; portainer.pagination_containers=25; portainer.pagination_images=25; _gat=1",
  "request_Referer": "http://192.168.56.102/portainer/",
  "request_User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36",
  "request_X-Forwarded-Prefix": "/portainer",
  "time": "2019-02-19T12:45:44Z"
}

无法正常工作:

{
  "BackendAddr": "",
  "BackendName": "Traefik",
  "BackendURL": {
    "Scheme": "",
    "Opaque": "",
    "User": null,
    "Host": "",
    "Path": "/frontend_latest/hass-icons-8b13a1ef.js",
    "RawPath": "",
    "ForceQuery": false,
    "RawQuery": "",
    "Fragment": ""
  },
  "ClientAddr": "192.168.56.1:58071",
  "ClientHost": "192.168.56.1",
  "ClientPort": "58071",
  "ClientUsername": "-",
  "DownstreamContentSize": 19,
  "DownstreamStatus": 404,
  "DownstreamStatusLine": "404 Not Found",
  "Duration": 100373,
  "FrontendName": "backend not found",
  "OriginContentSize": 19,
  "OriginDuration": 13969,
  "OriginStatus": 404,
  "OriginStatusLine": "404 Not Found",
  "Overhead": 86404,
  "RequestAddr": "192.168.56.102",
  "RequestContentSize": 0,
  "RequestCount": 78,
  "RequestHost": "192.168.56.102",
  "RequestLine": "GET /frontend_latest/hass-icons-8b13a1ef.js HTTP/1.1",
  "RequestMethod": "GET",
  "RequestPath": "/frontend_latest/hass-icons-8b13a1ef.js",
  "RequestPort": "-",
  "RequestProtocol": "HTTP/1.1",
  "RetryAttempts": 0,
  "StartLocal": "2019-02-19T12:46:54.875219779Z",
  "StartUTC": "2019-02-19T12:46:54.875219779Z",
  "downstream_Content-Type": "text/plain; charset=utf-8",
  "downstream_X-Content-Type-Options": "nosniff",
  "level": "info",
  "msg": "",
  "origin_Content-Type": "text/plain; charset=utf-8",
  "origin_X-Content-Type-Options": "nosniff",
  "request_Accept": "*/*",
  "request_Accept-Encoding": "gzip, deflate",
  "request_Accept-Language": "en-US,en;q=0.9",
  "request_Connection": "keep-alive",
  "request_Cookie": "_ga=GA1.1.364506726.1550080124; _gid=GA1.1.376969405.1550080124; portainer.UI_STATE=%7B%22dismissedInfoPanels%22%3A%7B%7D%2C%22dismissedInfoHash%22%3A%22y%2BAiiJOM%2Feqr4gyAl6VKBw%3D%3D%22%7D; pma_lang=en; portainer.pagination_containers=25; portainer.pagination_images=25",
  "request_Referer": "http://192.168.56.102/hass/",
  "request_User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36",
  "time": "2019-02-19T12:46:54Z"
}

怎么了? 为什么我得到404而不是200?

谢谢。

1 个答案:

答案 0 :(得分:0)

在第二种情况下,您拥有这个npm,它与任何"RequestLine": "GET /frontend_latest/hass-icons-8b13a1ef.js HTTP/1.1"不匹配,如果当您转到PathPrefixStrip时使用traefik重定向到/IP/hass ip,从我的角度来看,它会得到404,因为traefik对/frontend_latest/

没有任何规定