我目前正在一个项目上工作,其中我在Microsoft Azure上有一个虚拟机,并尝试使用Traefik反向代理的帮助下通过不同的路由访问多个Docker容器。除了反向代理之外,我需要的第一个服务是RabbitMQ,并且我应该能够在/rmq
路由上访问其用户界面。现在,我有以下的docker-compose文件来构建这两个服务:
version: "3.5"
services:
rabbitmq:
image: rabbitmq:3-alpine
expose:
- 5672
- 15672
volumes:
- ./rabbit/enabled_plugins:/etc/rabbitmq/enabled_plugins
labels:
- traefik.enable=true
- traefik.http.routers.rabbitmq.rule=Host(`HOST.com`) && PathPrefix(`/rmq`)
# needed, when you do not have a route "/rmq" inside your container (according to https://dev59.com/Q7fna4cB1Zd3GeqPx73-)
- traefik.http.routers.rabbitmq.middlewares=strip-docs
- traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq
- traefik.port=15672
networks:
- proxynet
traefik:
image: traefik:2.1
command: --api=true # Enables the web UI
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro
ports:
- 80:80
- 443:443
labels:
traefik.enable: true
traefik.http.routers.traefik.rule: "Host(`HOST.com`)"
traefik.http.routers.traefik.service: "api@internal"
networks:
- proxynet
以下是我的traefik.toml文件的内容:
logLevel = "DEBUG"
debug = true
[api]
dashboard = true
insecure = false
debug = true
[providers.docker]
endpoint = "unix:///var/run/docker.sock"
watch = true
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web-secure]
address = ":443"
[log]
level = "DEBUG"
format = "json"
< p > enabled_plugins
文件指定应激活哪些RabbitMQ插件。在这里,我有rabbitmq_management插件(以及其他插件),我认为需要访问RabbitMQ UI。我甚至检查了RabbitMQ容器的日志,显然rabbitmq_management已经正确启动:
rabbitmq_1 | 2021-01-30 15:50:30.538 [info] <0.730.0> Server startup complete; 7 plugins started.
rabbitmq_1 | * rabbitmq_stomp
rabbitmq_1 | * rabbitmq_federation_management
rabbitmq_1 | * rabbitmq_mqtt
rabbitmq_1 | * rabbitmq_federation
rabbitmq_1 | * rabbitmq_management
rabbitmq_1 | * rabbitmq_web_dispatch
rabbitmq_1 | * rabbitmq_management_agent
rabbitmq_1 | completed with 7 plugins.
rabbitmq_1 | 2021-01-30 15:50:30.539 [info] <0.730.0> Resetting node maintenance status
使用这些配置运行
docker-compose up
,如果我尝试访问HOST.com/rmq,则在浏览器控制台中会出现502 (Bad Gateway)错误。最初,这就是我卡住的地方。然而,在网上寻求帮助后,我发现了一种不同的方法来指定RabbitMQ容器标签上的traefik端口(traefik.http.services.rabbitmq.loadbalancer.server.port=15672
)。通过这个修改,我不再有Bad Request错误,但是在浏览器控制台上我得到了很多ERR_ABORTED 404 (Not Found)错误(以下列表不包含所有错误):rmq:7 GET http://HOST.com/js/ejs-1.0.min.js net::ERR_ABORTED 404 (Not Found)
rmq:18 GET http://HOST.com/js/charts.js net::ERR_ABORTED 404 (Not Found)
rmq:19 GET http://HOST.com/js/singular/singular.js net::ERR_ABORTED 404 (Not Found)
Refused to apply style from 'http://HOST.com/css/main.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
rmq:27 Uncaught ReferenceError: sync_get is not defined at rmq:27
我对这类项目没有太多经验,不确定我是否做错了什么或者这些配置中是否缺少某些内容,或者虚拟机本身的配置是否有问题。你知道我该怎么做才能通过URL HOST.com/rmq 访问RabbitMQ UI吗?
如果我成功运行它,我认为我也可以配置Docker仅允许通过路由访问Traefik UI,例如HOST.com/dashboard,而不是只能通过没有任何路由的URL访问。
提前致谢!