I'm using docker compose to build a project with django, nginx as services. When I launch the daphne server, and a client tries to connect to the websocket server, I get this error:
*1 recv() failed (104: Connection reset by peer) while reading response header from upstream
Client-side shows this
failed: Error during WebSocket handshake: Unexpected response code: 502
Here is my docker-compose.yml
version: '3'
services:
  nginx:
    image: nginx
    command: nginx -g 'daemon off;'
    ports:
      - "1010:80"
    volumes:
      - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
      - .:/makeup
    links:
      - web
  web:
    build: .
    command: /usr/local/bin/circusd /makeup/config/circus/web.ini
    environment:
      DJANGO_SETTINGS_MODULE: MakeUp.settings
      DEBUG_MODE: 1
    volumes:
      - .:/makeup
    expose:
      - '8000'
      - '8001'
    links:
      - cache
    extra_hosts:
      "postgre": 100.73.138.65
Nginx:
server {
        listen 80;
        server_name thelab518.cloudapp.net;
        keepalive_timeout 15;
        root /makeup/;
        access_log /dev/stdout;
        error_log /dev/stderr;
        location /api/stream {
            proxy_pass http://web:8001;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
location / {
        try_files $uri @proxy_to_app;
    }
    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://web:8000;
    }
And the circusd's web.ini file:
[watcher:web]
cmd = /usr/local/bin/gunicorn MakeUp.wsgi:application -c config/gunicorn.py
working_dir = /makeup/
copy_env = True
user = www-data
[watcher:daphne]
cmd = /usr/local/bin/daphne -b 0.0.0.0 -p 8001 MakeUp.asgi:channel_layer
working_dir = /makeup/
copy_env = True
user = root
[watcher:worker]
cmd = /usr/bin/python3 manage.py runworker
working_dir = /makeup/
copy_env = True
user = www-data