WebSockets

WebSockets is a method of providing bi-directional communication, similar to BOSH but with less overhead.

Configuration

WebSocket support is provided by mod_websocket, so uncomment or add "websocket" in your modules_enabled list to enable WebSockets.

With default HTTP settings the WebSocket connection endpoint will be avaliable at the following locations:

  • ws://example.com:5280/xmpp-websocket
  • wss://example.com:5281/xmpp-websocket

See documentation on HTTP settings for how to map HTTP Hosts to Prosody VirtualHosts, change the path or ports etc.

HTTP Proxy Passtrough

If you proxy WebSocket connections trough a HTTP proxy or server that handles HTTPS, you can set consider_websocket_secure = true to tell Prosody not to worry about the connections being unencrypted.

If you know how to configure other HTTP servers for WebSockets, let us know.

Nginx

See nginx websocket documentation.

location /xmpp-websocket {
    proxy_pass http://localhost:5280/xmpp-websocket;
    proxy_http_version 1.1;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Upgrade $http_upgrade;

    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_read_timeout 900s;
}

The Host header needs to be forwarded to allow to Prosody find the correct VirtualHost to use.

The X-Forwarded-For header lets Prosody to know the real IP. The IP of nginx must be included in the trusted_proxies config option.

The longer proxy_read_timeout prevents nginx from closing the connection if it remains silent for a while. A value higher than the socket framework network_settings.read_timeout setting is advisable. (default 840 seconds in trunk).