Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 1.39 KB

File metadata and controls

41 lines (33 loc) · 1.39 KB

SSL and custom hostname

In production, you'll want your server to run behind a real domain name and, ideally, over a secure SSL connection.

So instead of connecting to ws://localhost:8000, you'll want something like wss://my-game.io/live/.

Here's how to configure an Nginx reverse proxy to do just that:

  • Server setup: new Server(8042, 'localhost', new BinaryEncoder(events));
  • Client setup: new Client('wss://my-game.io/live/', new BinaryEncoder(events))
  • Nginx configuration:
server {
    listen 443 ssl http2;
    server_name my-game.io;
    root /home/tom32i/my-game/client;
    # ... the rest of the server and SSL configuration

    location /live/ {
        # Proxy for the running Netcode server
        proxy_pass http://localhost:8042/; # Address of the upstream Netcode server
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header 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_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }

    location / {
        # Serve the static HTML/JS/CSS assets
        index index.html;
    }
}

The same Nginx block works for both the Node and the Go Netcode servers — only the proxy_pass target changes.