I'm trying to set up a reverse proxy for my NestJS back-end running on port 5000. Said back-end has support for regular rest requests as well as a websocket gateway with socket.io. SSL was set-up with Certbot. Requests coming to the root address get served a landing page, and I want requests coming to https://mydomain/api to get proxied to the NestJS backend. Client is a Flutter mobile app.
This is my current configuration:
server {
root /path/to/landing/page;
index index.html index.htm index.nginx-debian.html;
server_name mydomain; # managed by Certbot
location /api/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:5000/;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate */fullchain.pem; # managed by Certbot
ssl_certificate_key */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
}
Requests coming to https://mydomain get served the landing page and requests coming to https://mydomain/api get proxied to the NestJS back-end, but the websocket portion does not work. Regular GET and POST requests work fine, but when trying to connect via websockets, the connection just hangs.
When I set the request URL on the front-end to http://mydomain:5000 both rest requests and websocket connection work fine.
What am I missing?
Note: Hosting back-end on AWS EC2 Ubuntu 18.04 instance.