gpt4 book ai didi

azure - 无法访问 docker 容器上的 RabbitMQ UI

转载 作者:行者123 更新时间:2023-12-04 08:10:48 27 4
gpt4 key购买 nike

我目前正在开发一个项目,在 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://stackoverflow.com/questions/59054551/how-to-map-specific-port-inside-docker-container-when-using-traefik)
- 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"

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(错误网关) 我的浏览器控制台上出现错误。最初,这就是我被困住的地方。然而,在网上搜索一些帮助后,我发现了一种在 RabbitMQ 容器标签上指定 traefik 端口的不同方法 (traefik.http.services.rabbitmq.loadbalancer.server.port=15672),并且,通过此修改,我不再遇到错误请求错误,但我在浏览器的控制台上收到很多 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 配置为仅允许通过 HOST.com/dashboard 等路由访问 Traefik UI,而不是访问它仅包含 URL,不包含任何路由。

提前致谢!

最佳答案

解决了。我不知道为什么,但是当我使用配置traefik.http.services.rabbitmq.loadbalancer.server.port=15672时,我更改了行的顺序 traefik.http.routers.rabbitmq.middlewares=strip-docstraefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq ,使得prefix出现在 middleware 之前。更改了这一点,现在我可以在 HOST.com/rmq 上访问 RabbitMQ UI 。所以我的最后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://stackoverflow.com/questions/59054551/how-to-map-specific-port-inside-docker-container-when-using-traefik)
- traefik.http.routers.rabbitmq.middlewares=strip-docs
- traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq
- traefik.http.services.rabbitmq.loadbalancer.server.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

我会将这个问题标记为已解决,但如果您知道为什么这两行的顺序很重要,请解释一下以供将来引用。

谢谢!

关于azure - 无法访问 docker 容器上的 RabbitMQ UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65971814/

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