map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

map $http_x_forwarded_proto $forwarded_proto {
    default $http_x_forwarded_proto;
    '' $scheme;
}

upstream chatroom_app {
    server chatroom-app:8000;
}

server {
    listen 80;
    server_name _;

    location / {
        proxy_pass http://chatroom_app;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        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-Proto $forwarded_proto;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Port $server_port;

        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
    }
}
