Nginx + Nodejs + Let’s Encrypt + Socket.io

Nginx Reverse Proxy Configuration for Websocket on SSL

upstream app_name {
  server example.com:3333;
}

upstream websocket_server {
  server example.com:3333;
}

# HTTP Server
server {
  listen 80   default_server;
  server_name example.com;
  return      301 https://$host$request_uri;
}

# HTTPS Server
server {
  listen      443 default_server ssl;
  server_name example.com;
  root        /home/admin/web/site_folder;

  location / {
    proxy_pass       http://app_name;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_set_header   Host $host;
  }

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
}

post via Codincafe