CLOUD PAAS / DEVELOPMENT TOOLS

WebSockets Support

This guide has been reviewed and reformatted for Ruk-Com Cloud PaaS. Screens may vary slightly by platform version.

Click or tap a screenshot to view it at its original size.

Objective

This guide explains how to use WebSockets Support on Ruk-Com Cloud PaaS, with ordered procedures and practical verification points.

Before you begin

  • Sign in with an account permitted to manage the relevant environment.
  • Confirm the target environment, region and resources before saving changes.
  • Create a backup or rollback plan before changing a production system.

WebSocketsIt is a famous technology website. This creates a continuous, full-duplex connection between the client and server by sending messages in both directions immediately at a negligible cost. Communication over this TCP-based protocol introduces latency.latencyIts connectivity is very low and it responds quickly, making your applications faster and more efficient.

You can avail the following benefits from WebSockets:

  • Reduce response delays and unnecessary network traffic. This is due to full-duplex distribution over a single connection.
  • Streaming bypasses both upstream and downstream proxies and firewalls in one pass.
  • Backward compatibility with pre-WebSocket By changing from HTTP connections to WebSockets

Ruk-Com Cloud provides advanced components to support WebSockets by combining the technology withShared Load BalancerandNGINX-balancer nodeYou can use it even without adding an external IP address to your server app.

The easiest way for enabling WebSockets is to place the NGINX balancer in front of your application, making it the starting point environment and eliminating any additional configuration. This server can also be used to easily override default settings with manual configuration, such as changing the listener's port number.

However, WebSockets technology is also supported by the application servers we provide, with examples of proper configurations being as follows:

The instructions below will provide insights on how to configure WebSockets for your application using Node.NGINX-balancerFor example, we will use a simple chat application written in PHP, so let's start step by step.

Creating the Environment and Deploying Applications

1. Log in to the Ruk-Com Cloud Dashboard with your credentials and clickNew Environmenttop left

Ruk-Com Cloud PaaS procedure screenshot

2. inEnvironment TopologyYou should create the environment to suit the needs of your application (for example, we choose an application server,Apachefor our PHP app), the only required element isNGINX-balancer

Then set the resource usage limit for the selected node using the cloudlet slider, enter an environment name (e.g.balancer-websockets) and clickCreate

Ruk-Com Cloud PaaS procedure screenshot

3. Wait a moment for your new environment to appear in the dashboard.

Ruk-Com Cloud PaaS procedure screenshot

4. Upload and Deploy your application to the desired context. (Default isROOT) by using archive/URL or via remote VCS repository or related usage instructions can be found atDeployment manual

Configuring NGINX Balancer

In this section we will walk you through an example configuration from Jelastic by modifying the default proxy settings at NGINX-balancer. To determine where incoming requests should be redirected and to enable WebSockets streaming

1. Click the buttonConfigAt the NGINX-balancer node

2. Open the filenginx-jelastic.confin the directoryconfFind the location block in the first section of server code, place the following line first:

location /ws/ {
   proxy_pass http://{appserver_ip}:{port};
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
}

where

  • {appserver_ip}- The IP address of the application server node where you deploy the WebSockets app. You can click the expand node button to see your IP address.
  • {port}- The port number on which your application listens.

For example, the settings are as shown in this picture.

Note:Normally we recommend editing the configuration in the nginx.conf file and keeping the contents of nginx-jelastic.conf as a setting default/backup But in this case it is a necessary and relatively simple change that works directly with the file. nginx-jelastic will make it easier

3. This is all to configure NGINX. Don't forget to press the button.Saveto save changes and press the buttonRestartat balancer node

Application configuration

Once Websocket is enabled, you will need to configure the application by adjusting code similar to the steps below to specify the correct connection string based on the location of the new WebSocket file:

1. Click the buttonConfignext to your server application.

2. In the tabConfiguration ManagerYou can access the application's files by going to the folder.webroot/ROOT(or a different folder if you customize the context while deploying the application)

Open the file to specify WebSockets settings and adjust them.wspath according to this format:

ws://{env_domain}{path_to_ws_file}

Value{env_domain} should be replaced with the environment domain name (can be viewed under environment name on the dashboard) and the value{path_to_ws_file}It should lead to the file which needs to be accessed when creating the WebSockets connection.

For example:

Don't forget to press the button.Saveto complete the operation

3. The final stepRestartyour server application to adjust the new configuration.

4. When the app is Running again, you can clickOpen in Browsernext to your environment to access the application.

5. You will see a small active chat window where you can send and receive messages in real time without having to refresh your browser tab.