我有一个带有子域的VM - 例如mysubdomain.notmydomain.com,在下面的日志中可见 - 运行单个节点Docker Swarm(为简单起见)并使用Traefik作为各种服务的反向代理。我设法将我的问题简化为现在我在这里分享的不同服务。
预期的行为:我得到mysubdomain.notmydomain.com/test,我看到一个带有文字和渲染徽标的回复。
实际行为::我看到链接断开(见照片)
版本
Ubuntu 16.04.1 LTS xenial
Docker版本18.03.0-ce,build 0520e24
Traefik 1.5.4
截断的docker-compose文件
version: '3.4'
services:
test:
image: tutum/hello-world
networks:
- traefik-network
deploy:
labels:
traefik.enable: "true"
traefik.backend: "test"
traefik.docker.network: "cat_traefik-network"
traefik.frontend.rule: "Host:mysubdomain.notmydomain.com;PathPrefix:/test"
traefik.port: 80
traefik.frontend.passHostHeader: "true"
traefik.domain: "mysubdomain.notmydomain.com"
traefik:
image: traefik
ports: ["80:80", "443:443", "8080:8080"]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik/traefik.toml:/traefik.toml
- ./traefik/acme.json:/acme.json
networks:
- traefik-network
- mosquitto-network
command:
--api \
--docker \
--docker.swarmmode \
--docker.domain=mysubdomain.notmydomain.com \
--docker.watch \
--logLevel=DEBUG
deploy:
placement:
constraints: [node.role==manager]
labels:
traefik.enable: "false"
显示意外行为的屏幕截图
来自Traefik的日志
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/test","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/test","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}" ForwardURL=http://10.0.2.7:80
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/forward: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"10.0.2.7:80","Path":"","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/forward/http: begin ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"10.0.2.7:80","Path":"","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/forward/http: Round trip: http://10.0.2.7:80, code: 200, Length: 478, duration: 8.138087ms"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/forward/http: completed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"10.0.2.7:80","Path":"","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/forward: completed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"http","Opaque":"","User":null,"Host":"10.0.2.7:80","Path":"","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
cat_traefik.1.ifbq38ugx76r@cat | time="2018-04-03T20:42:39Z" level=debug msg="vulcand/oxy/roundrobin/rr: competed ServeHttp on request" Request="{"Method":"GET","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/test","RawPath":"","ForceQuery":false,"RawQuery":"","Fragment":""},"Proto":"HTTP/1.1","ProtoMajor":1,"ProtoMinor":1,"Header":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-GB,en-US;q=0.9,en;q=0.8"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Cookie":["redirect_to=%252F"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"]},"ContentLength":0,"TransferEncoding":null,"Host":"mysubdomain.notmydomain.com","Form":null,"PostForm":null,"MultipartForm":null,"Trailer":null,"RemoteAddr":"10.255.0.2:54617","RequestURI":"/test","TLS":null}"
日志显示前几个请求包含Path:/test
,而最后一个请求包含Path:/
。我认为这是出了什么问题。
问题:我需要重新配置如何或者什么才能在包含logo.png的tutum/hello-world
容器上正确加载辅助请求?
tutum/hello-world
图像正在进行测试并作为一个明显的例子;实际的堆栈包含mosquitto,grafana,Influxdb和一些显示相同root行为的自定义服务。 (那些有frontend.rule的)`
任何建议都表示赞赏;我可以在需要时提供更多信息。
答案 0 :(得分:0)
来自#3124的Github问题Julien Salleyron:
感谢您对Træfik的兴趣!
这不是问题。 Træfik不会重写响应体。我们认为 在反向代理中重写响应主体的过程是 太重/容易出错。
我们鼓励您:
- 仅使用基于主机的规则(对于您的用例似乎不可能)
- 在您的应用中使用特定的Traefik路径重写标题(X-Forwarded-Prefix,X-Replaced-Path)
- 让您的应用听取特定路径