问题
Some of my frontends aren't routed properly to backend. I do have 2 container: - portainer; - homeassistant; Portainer works properly but homeassistant is not routed properly to backend.
my 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 file:
[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
The below are 2 different access logs:
working one:
{
"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"
}
not working properly:
{
"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"
}
What's wrong ? Why I get a 404 and not the a 200 ?
Thank you in advance.
回答1:
In the second case, you have this "RequestLine": "GET /frontend_latest/hass-icons-8b13a1ef.js HTTP/1.1"
, this doesn't match any PathPrefixStrip
, if when you go to /IP/hass
you redirect to /frontend_latest/
using the traefik ip, from my point of view gets a 404, because traefik doesn't have any rule for /frontend_latest/
来源:https://stackoverflow.com/questions/54768025/traefik-doesnt-route-to-proper-backend-for-some-containers