Websockets Support
WebSockets Support
The platform supports WebSockets through the Shared Load Balancer, NGINX load balancer, and compatible application servers. Using an NGINX balancer is the simplest option because it can act as the environment entry point without requiring a Public IP on the application server.
Create the Environment
1Open the environment wizard
Sign in to the platform dashboard and click New environment.
2Select the required topology
Choose the application server required by the application, add an NGINX load balancer, configure the Cloudlet limits, enter the environment name, and click Create.
Wait until the new environment appears in the dashboard and all nodes reach the running state.
Deploy the Application
Upload and deploy the WebSocket application to the required application context. The example uses the default ROOT context, but another context can be selected when required.
- Upload an application archive or provide its URL.
- Alternatively, deploy the project from a remote VCS repository.
- Confirm that the project appears in the Deployed column.
Configure the NGINX Balancer
The default NGINX proxy settings must be extended so WebSocket requests are sent to the correct application-server IP and port.
1Open the NGINX configuration
Click Config for the NGINX balancer.
2Find the application-server IP
Open the additional node information for the application server and copy its internal IP address.
3Add the WebSocket location block
Open conf/nginx-jelastic.conf. Inside the first server section, add this block before the existing main location section:
location /ws/ {
proxy_pass http://{appserver_ip}:{port};
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
{appserver_ip}— internal IP of the application-server node.{port}— port on which the WebSocket application listens.
nginx.conf and preserve nginx-jelastic.conf as the platform-generated configuration. The source example edits nginx-jelastic.conf directly because the change is limited.
4Save and restart NGINX
Save the file and restart the balancer nodes.
Configure the Application
1Open the application files
Click Config for the application server.
Navigate to webroot/ROOT, or to the folder corresponding to the custom deployment context, and open the file containing the WebSocket connection settings.
2Update the WebSocket URI
Configure the connection string in this format:
ws://{env_domain}{path_to_ws_file}
{env_domain}— environment domain displayed below the environment name in the dashboard.{path_to_ws_file}— route or file used when establishing the WebSocket connection.
Save the application file and restart the application-server node.
Open and Test the Application
1Open the application
After the application server is running again, click Open in Browser.
Test the application by sending and receiving real-time messages. The example chat works without reloading the browser page.
wss:// instead of ws://.
