我有一个在端口8080上运行的服务,该服务同时接受http和gRPC。我了解traefik中的gRPC存在一些限制,因此这是最终目标。
如果我能做到这一点,我相信我可以完成下一部分:
对于配置,我正在使用docker compose文件。
version: "3.2"
services:
reverse-proxy:
image: traefik:v2.2
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.dgraph.address=:8080"
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
# there is another service here `zero` that is not using traefik so I ommitted its config.
alpha:
image: dgraph/dgraph:master
volumes:
- /dgraph/data:/dgraph
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.adminIps.ipwhitelist.sourcerange=1.1.1.1" # my ip address instead of 1.1.1.1
- "traefik.http.routers.alpha.rule=Host(`api.mydomain.com`) && Path(`/graphql`)"
- "traefik.http.routers.alpha.entrypoints=dgraph"
- "traefik.http.routers.schema.rule=Host(`api.mydomain.com`) && Path(`/admin/schema`)"
- "traefik.http.routers.schema.middlewares=adminIps@docker"
- "traefik.http.routers.schema.entrypoints=dgraph"
- "traefik.http.routers.all.rule=Host(`api.mydomain.com`)"
- "traefik.http.routers.all.middlewares=adminIps@docker"
- "traefik.http.routers.all.entrypoints=dgraph"
restart: always
command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --whitelist 172.0.0.0:172.254.254.254
我尝试在端口80上创建另一个入口点,然后在路由器中使用该入口点,并添加了负载均衡器,但这似乎不起作用。这是修改后的配置:
version: "3.2"
services:
reverse-proxy:
image: traefik:v2.2
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.dgraph.address=:8080"
- "--entrypoints.web.address=:80"
ports:
- "8080:8080"
- "80:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
# there is another service here `zero` that is not using traefik so I ommitted its config.
alpha:
image: dgraph/dgraph:master
volumes:
- /dgraph/data:/dgraph
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.adminIps.ipwhitelist.sourcerange=1.1.1.1" # my ip address instead of 1.1.1.1
- "traefik.http.routers.alpha.rule=Host(`api.mydomain.com`) && Path(`/graphql`)"
- "traefik.http.routers.alpha.entrypoints=web"
- "traefik.http.services.alpha.loadbalancer.server.port=80"
- "traefik.http.routers.schema.rule=Host(`api.mydomain.com`) && Path(`/admin/schema`)"
- "traefik.http.routers.schema.middlewares=adminIps@docker"
- "traefik.http.routers.schema.entrypoints=dgraph"
- "traefik.http.routers.all.rule=Host(`api.mydomain.com`)"
- "traefik.http.routers.all.middlewares=adminIps@docker"
- "traefik.http.routers.all.entrypoints=dgraph"
restart: always
command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --whitelist 172.0.0.0:172.254.254.254
上面的第一个docker-compose.yml文件有效。所谓工作,是指它正确地将路由,规则和中间件全部应用于端口8080。
上面的第二个docker-compose.yml文件我希望打开端口80并应用规则将http api.mydomain.com/graphql路由到alpha:8080 / graphql。但是,这不会发生。当我用docker-compose up -d
向上推时没有出现任何错误,但是当我使用yougetsignal.com并检查端口80是否打开时,得到的响应是端口80已关闭,而当我尝试使用端口8080时,在使用路由全部(api.mydomain.com:8080)之前,我在浏览器“ Bad Gateway”中收到响应
答案 0 :(得分:0)
您说您的服务Alpha正在监听8080
,因此您应该在loadbalancer
中使用它:
"traefik.http.services.alpha.loadbalancer.server.port=8080"
您可以这样想:entrypoint
是传入连接,loadbalancer
是Traefik重定向请求的位置。