[英]GET Request on Docker Traefik API - Block by CORS rules
I've got trouble finding how to reach my Traefik API using GET request from an other docker container.我在寻找如何使用来自其他 docker 容器的 GET 请求访问我的 Traefik API 时遇到了麻烦。
Context语境
I have 2 docker container, one running a traefik instance :我有 2 个 docker 容器,一个运行 traefik 实例:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 80:80 -l traefik.frontend.rule=Host:my.server -l traefik.port=80 --name traefik traefik --docker --api
The other container run a quite simple React web application.另一个容器运行一个非常简单的 React Web 应用程序。 I'm trying to reach the Traefik API using XMLHttpRequest .
我正在尝试使用XMLHttpRequest访问 Traefik API。
My request is blocked by the Traefik CORS Policy.我的请求被 Traefik CORS 政策阻止。 Any idea on how configure Traefik to enable Access-Control-Allow-Origin ?
关于如何配置 Traefik 以启用 Access-Control-Allow-Origin 的任何想法?
The only way I've done this is by wiring the Access-Control-Allow-Origin
header as a label in the Træfik container.我完成此操作的唯一方法是将
Access-Control-Allow-Origin
标头连接为 Træfik 容器中的标签。
traefik.frontend.headers.customResponseHeaders=Access-Control-Allow-Origin:*
And if you need to add more headers like Access-Control-Allow-Method
, you must concatenate them with double bars ( ||
) in the same rule.如果您需要添加更多标题,如
Access-Control-Allow-Method
,则必须在同一规则中使用双杠 ( ||
) 将它们连接起来。
traefik.frontend.headers.customResponseHeaders=Hdr1:val1,val2||Hdr2:val3
So your docker run line would be as follows.因此,您的docker run行将如下所示。
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-p 8080:8080 -p 80:80 \
-l traefik.frontend.rule=Host:my.server \
-l traefik.port=80 \
-l "traefik.frontend.headers.customResponseHeaders=Access-Control-Allow-Origin:*" \
--name traefik traefik --docker --api
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.