upstream cryps {
    server 127.0.0.1:40000;
}

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

server {
    root /home/git/cryps/client/dist/;
    index index.html;

    server_name cryps.gg; # managed by Certbot

    location / {
        try_files $uri $uri/ =404;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/cryps.gg/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/cryps.gg/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location /ws {
        proxy_pass http://cryps;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 600s;
    }
}

server {
    if ($host = cryps.gg) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80 ;
    listen [::]:80 ;
    server_name cryps.gg;
    return 404; # managed by Certbot
}
