nginxtraefikserver-sent-eventsdaphne

Traefik conf for server-side events


I'm trying to set a server-side event correctly with Traefik to no avail. I have a Django server that has a URL that sends sse, I can proxy easily with nginx with this simple conf:

server {
  listen 80;
  server_name _ ;
  charset utf-8;
  client_max_body_size 20M;

  location / {
    proxy_pass http://django:8000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
  }
}

In traefik using docker labels I set:

    labels:
       - "traefik.enable=true"
       - "traefik.http.routers.dj.rule=Host(`$HOST_ADK`)"
       - "traefik.http.routers.dj.entrypoints=web"
       - "traefik.http.routers.dj.service=dj"
       - "traefik.http.services.dj.loadbalancer.server.port=8000" 
       #- "traefik.http.routers.dj.middlewares=compress-no-stream"
       #- "traefik.http.middlewares.compress-no-stream.compress=true"
       #- "traefik.http.middlewares.compress-no-stream.compress.excludedcontenttypes=text/event-stream"

This resolve to internal server error. When proxying to django run with runserver (ie non Daphne that is used in the docker) I get a "Temporary failure in name resolution" and I cannot understand what it refers to.

Any hint on what's the correct configuration to make Server-Sent event work?


Solution

  • It turns out that Django's view that responded with the sse was setting 2 identical headers and that makes Traefik bristle.

    Complete explanation on the issue.

    Once fixed the headers everything worked.