gpt4 book ai didi

docker - Traefik 路径中的服务不会重定向到服务路径以获取其他请求

转载 作者:行者123 更新时间:2023-12-02 20:05:45 31 4
gpt4 key购买 nike

我有一个带有子域的虚拟机 - 例如mysubdomain.notmydomain.com,如下面的日志所示——运行单节点 Docker Swarm(为简单起见)并使用 Traefik 作为各种服务的反向代理。我设法将不同服务的问题简化为我现在在这里分享的问题。
预期行为:我访问了 mysubdomain.notmydomain.com/test,我看到了带有文本和渲染 Logo 的响应。
实际行为::我看到一个断开的链接(见图)
版本

Ubuntu 16.04.1 LTS xenial

Docker version 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"
显示意外行为的屏幕截图
Proof of error
来自 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:/ .我认为这就是问题所在。
问题:我需要如何或什么重新配置才能在 tutum/hello-world 上获得辅助请求包含 logo.png 的容器是否正确加载? tutum/hello-world选择图像进行测试并作为一个明显的例子;实际堆栈包含 mosquitto、grafana、influxdb 和一些自定义服务,它们都显示相同的根行为。 (那些有frontend.rule的)`
任何建议表示赞赏;我可以在需要时提供更多信息。

最佳答案

来自 Github 问题 #3124Julien Salleyron :

Thanks for your interest in Træfik!

It's not an issue. Træfik does not rewrite the response body. We think that the process of rewriting the response body in a reverse proxy is too heavy/prone to errors.

We encourage you to either:

  • use host based rules only (seems impossible for your use case)
  • use specific Traefik path rewrite headers in you app (X-Forwarded-Prefix, X-Replaced-Path)
  • let your app listen on a specific path

关于docker - Traefik 路径中的服务不会重定向到服务路径以获取其他请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49639772/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com