在Traefik后面运行Graylog

时间:2019-06-12 11:58:48

标签: reverse-proxy traefik graylog2 graylog

我一直在使用Traefik作为通过docker compose管理的多个容器的反向代理。它运行良好,但是在使Graylog在其后正确运行方面有些困难。

此配置(完整文件的一部分,删除了不相关的服务)对我有用

version: '3'

services:
  traefik:
    image: traefik 
    command: --docker 
    networks:
      - web
    ports:
      - "80:80"     
      - "8080:8080" 
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  graylog:
    image: graylog/graylog:3.0
    environment:
      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
      - GRAYLOG_ROOT_PASSWORD_SHA2=somestuffhere
      - GRAYLOG_HTTP_BIND_ADDRESS=0.0.0.0:9000
      - GRAYLOG_HTTP_EXTERNAL_URI=http://graylog.localhost/
    links:
      - mongodb:mongo
      - elasticsearch
    depends_on:
      - mongodb
      - elasticsearch
    networks:
      - web
      - default
    ports:
      - 9000:9000
      - 1514:1514
      - 1514:1514/udp
      - 12201:12201
      - 12201:12201/udp
    labels:
      - "traefik.docker.network=web"
      - "traefik.web.frontend.rule=Host:graylog.localhost"
      - "traefik.protocol=http"
      - "traefik.port=9000"
      - "traefik.enable=true"

然后我可以在http://graylog.localhost/的浏览器中访问Graylog

出现问题是因为我无法在暂存环境中使用像这样的域。我不得不使用的是paths而不是domains,例如我的暂存环境中的招摇服务定义为

swagger:
    image: swaggerapi/swagger-ui
    environment:
      SWAGGER_JSON: /swagger/staging-openapi.yaml
      BASE_URL: /swagger
    volumes:
      - /home/ubuntu/src/carelink_swagger_service:/swagger
    networks:
      - web
      - default
    labels:
      - "traefik.docker.network=web"
      - "traefik.frontend.rule=Host:my.staging.domain.org; PathPrefix: /swagger"
      - "traefik.protocol=http"
      - "traefik.port=8080"
      - "traefik.enable=true"

我访问了类似https://my.staging.domain.org/swagger/

的服务

尝试将这种方法用于Graylog

graylog:
    image: graylog/graylog:3.0
    environment:
      - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
      - GRAYLOG_ROOT_PASSWORD_SHA2=somestuffhere
      - GRAYLOG_HTTP_BIND_ADDRESS=0.0.0.0:9000
      - GRAYLOG_HTTP_EXTERNAL_URI=http://localhost/graylog/
    links:
      - mongodb:mongo
      - elasticsearch
    depends_on:
      - mongodb
      - elasticsearch
    networks:
      - web
      - default
    ports:
      - 9000:9000
      - 1514:1514
      - 1514:1514/udp
      - 12201:12201
      - 12201:12201/udp
    labels:
      - "traefik.docker.network=web"
      - "traefik.web.frontend.rule=Host:localhost; PathPrefix: /graylog"
      - "traefik.protocol=http"
      - "traefik.port=9000"
      - "traefik.enable=true"

出现以下错误

enter image description here

我已经在Graylog论坛等上浏览过Q/Asimilar entries,但是我感觉好像在追逐自己的尾巴。

1 个答案:

答案 0 :(得分:0)

它适用于Traefik 2.x,但我认为您将设法转换规则:

      labels:
        - "traefik.http.routers.graylog.rule=PathPrefix(`/graylog`)"
        - "traefik.http.routers.graylog.middlewares=graylog3@docker,graylog2@docker,graylog@docker"
        - "traefik.http.middlewares.graylog3.stripprefix.prefixes=/graylog"
        - "traefik.http.middlewares.graylog2.redirectregex.regex=^(.*)/graylog$$"
        - "traefik.http.middlewares.graylog2.redirectregex.replacement=$$1/graylog/"
        - "traefik.http.middlewares.graylog.replacepathregex.regex=^/graylog/(.*)"
        - "traefik.http.middlewares.graylog.replacepathregex.replacement=^/$$1"
        - "traefik.http.routers.graylog.service=graylog"
        - "traefik.http.services.graylog.loadbalancer.server.port=9000"
        - "traefik.docker.network=traefik"