添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I'm trying to use pihole (dockerized, behind traefik) with homer which is a dashboard, which accesses the pihole api to get stats. But the CORS is preventing this call. I added CORS headers in traefik, but now the api.php returns a Failed CORS: homer_fqdn vs ip,pihole_fqdn. While using with nginx, I bypassed this with a custom fastcgi_param HTTP_ORIGIN ""; , but cant seem to figure out for lighttpd 15-fastcgi-php.conf.

What is the right way to get CORS working?

For my pi-hole docker instances, I set the CORS hosts as follows:

CORS_HOSTS=example.com,homer.example.com,homeassistant.example.com

For my traefik docker instance, I created a file called "cors.yaml" with the following:

http:
  middlewares:
    example-com-cors:
      headers:
        accessControlAllowHeaders: "*"
        accessControlAllowMethods:
          - GET
          - OPTIONS
          - PUT
        accessControlAllowOriginListRegex:
          - https://(.*)?example\.com(.*)
        accessControlMaxAge: 100
        addVaryHeader: true

My homer compose.yaml file - and any other containers that need to enable CORS - has the following labels added:

    labels:
      # Traefik
      - "traefik.enable=true"
      - "traefik.http.routers.homer-rtr.rule=Host(`${HOSTNAME1}.${DOMAINNAME}`)"
      - "traefik.http.routers.homer-rtr.entrypoints=websecure"
      - "traefik.http.routers.homer-rtr.middlewares=example-com-cors@file"
      - "traefik.http.routers.homer-rtr.service=homer-srv"
      - "traefik.http.routers.homer-rtr.tls=true"
      - "traefik.http.services.homer-srv.loadbalancer.server.port=${WEBPORT1}"
      - "traefik.http.services.homer-srv.loadbalancer.server.scheme=http"

Here are my labels for one of my pi-hole instances:

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.pihole-1-rtr.rule=Host(`${HOSTNAME}.${DOMAINNAME}`)"
      - "traefik.http.routers.pihole-1-rtr.entrypoints=websecure"
      - "traefik.http.routers.pihole-1-rtr.middlewares=example-com-cors@file"
      - "traefik.http.routers.pihole-1-rtr.service=pihole-1-srv"
      - "traefik.http.routers.pihole-1-rtr.tls=true"
      - "traefik.http.services.pihole-1-srv.loadbalancer.server.port=${WEBPORT}"
      - "traefik.http.services.pihole-1-srv.loadbalancer.server.scheme=http"

That has resolved the issue for any target that requires CORS.