Websockets Support

WebSockets Support

WebSockets establish a continuous, full-duplex connection between a client and server. This allows bidirectional messages to be transferred with low overhead, low latency, and no need to refresh the browser repeatedly.
Lower Latency Reduce response delays by exchanging data instantly over one persistent connection.
Efficient Traffic Avoid unnecessary repeated HTTP requests and reduce network overhead.
Proxy Compatibility Support simultaneous upstream and downstream streaming through proxies and firewalls.

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.

New environment button
Start creating the WebSockets environment from the dashboard.

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.

Required component: The NGINX load balancer is the essential element in this configuration because it receives WebSocket requests and forwards them to the application server.
WebSockets environment topology
Example topology with an NGINX balancer and Apache PHP application server.

Wait until the new environment appears in the dashboard and all nodes reach the running state.

WebSockets environment created
The created environment contains the application server and NGINX balancer.

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.
WebSockets application deployed
The project has been deployed to the application server.

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.

NGINX Config button
Open Configuration Manager for the NGINX balancer.

2Find the application-server IP

Open the additional node information for the application server and copy its internal IP address.

Application server internal IP
Use the application-server IP in the NGINX proxy configuration.

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 WebSockets configuration
Example WebSocket proxy settings inside nginx-jelastic.conf.
For larger or more complex customisations, it is normally safer to edit 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.

Restart NGINX nodes
Restart NGINX to activate the new proxy configuration.

Configure the Application

1Open the application files

Click Config for the application server.

Apache Config button
Open the application-server Configuration Manager.

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.
WebSocket URI in the PHP application
Update the application’s WebSocket URI to use the environment domain and configured WebSocket path.

Save the application file and restart the application-server node.

Restart Apache nodes
Restart the application server to apply the updated WebSocket URI.

Open and Test the Application

1Open the application

After the application server is running again, click Open in Browser.

Open WebSocket application in browser
Launch the application from the dashboard.

Test the application by sending and receiving real-time messages. The example chat works without reloading the browser page.

WebSockets chat application
The application exchanges messages in real time through the WebSocket connection.
Secure applications: When the application is served over HTTPS, use the secure WebSocket scheme wss:// instead of ws://.

What’s next?