【问题标题】:How to run Matomo behind Traefik with sub path?如何使用子路径在 Traefik 后面运行 Matomo?
【发布时间】:2019-09-23 14:43:11
【问题描述】:

我正在设置一个使用 Traefik (v1.7.16) 作为反向代理的 docker-compose 环境,并希望包含 Matomo。我将 Bitnami 图像用于 Matomo 和备份数据库 (MariaDB);两个latest。设置类似于Bitnami's example compose file

我按照提供的说明进行操作,一切正常,除了使用 Traefik 进行路由。例如。我可以在localhost:<exposedPort> 运行 Matomo,但不能在 localhost/matomo 运行,因此子路径不起作用。

到目前为止我所做的:正如Matomo FAQ 中所解释的,我将环境变量MATOMO_ENABLE_PROXY_URI_HEADER=yes 设置为config.ini.php 中的proxy_uri_header = 1(这可行)。然后我为 Matomo 服务设置 traefik 标签:

labels:
  - 'traefik.backend=matomo'
  - 'traefik.docker.network=proxy_traefik'
  - 'traefik.enable=true'
  - 'traefik.frontend.headers.STSPreload=true'
  - 'traefik.frontend.headers.STSSeconds=31536000'
  - 'traefik.frontend.rule=Host:localhost; PathPrefixStrip:/matomo;'
  - 'traefik.frontend.headers.customRequestHeaders=X-Forwarded-Uri:localhost/matomo'
  - 'traefik.frontend.headers.hostsProxyHeaders=X-Forwarded-Uri'
  - 'traefik.port=80'

因此,我可以加载页面 localhost/matomo,但所有内部 URL(如图像和脚本 URL)仅引用 localhost,不包括路径 /matomo

在设置 Traefik 和 Matomo 时我有什么遗漏吗?

【问题讨论】:

    标签: routing docker-compose traefik bitnami matomo


    【解决方案1】:

    过去一周左右,我自己一直在努力解决这个问题,终于解决了。
    和 OP 一样,我还在使用 traefik v1.7,刚刚发现了 Matomo,想把它连接到我为自己设置的 gitea 容器上。

    我的 traefik 前端规则标签如下所示:

        labels:
          traefik.frontend.rule: 'HostRegexp: ${DOMAIN_NAME}, {subdomain:[a-z]+}${DOMAIN_NAME}; PathPrefixStrip:/matomo/'
    

    这是一种特殊情况,因为我希望 matomo 始终位于我使用的任何主机名上,只要我将 /matomo/ 添加到 URL。

    一个更简单的版本是:

        labels:
          traefik.frontend.rule: 'Host: ${DOMAIN_NAME}; PathPrefixStrip:/matomo/'
    

    您可以在 .env 文件中定义 DOMAIN_NAME,或者直接替换为 localhost 以匹配您的示例。

    对我来说改变的是最后一个斜杠,没有它访问 matomo 会失败。

    【讨论】:

      【解决方案2】:

      通过查看您的描述和此处的配置 sn-ps 可以看出,您需要的是 PathPrefix-Rule,而不是 PathPrefixStrip-Rule。这样,内部 URL 应该在 localhost/matomo 之后添加,因为 matomo(您的前缀)在被反向代理到后端之前不会剥离。 p>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-03
        • 1970-01-01
        • 1970-01-01
        • 2018-09-13
        • 1970-01-01
        • 2022-10-25
        相关资源
        最近更新 更多