CLOUD PAAS / DEVELOPMENT TOOLS

Websockets Support for Apache & NGINX

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 for Apache & NGINX 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 ubiquitous client-server technology that enables instant message exchange and interaction within your application by establishing a continuous, full-duplex TCP connection between the server and the client's browser. Using such communication channels results in very low latency and fast interactions. Ensures that streaming passes through proxies and firewalls both upstream and downstream at the same time.

Ruk-Com Cloud provides advanced WebSockets and enhances this by integrating this technology with Shared Load Balancer and NGINX-balancer. So you can use it even without an external IP address attached to your server by proxying the ports used by WebSockets apps to a single port - 80 for HTTP and 443 for HTTPS.

The simplest way to use WebSockets for applications is to placeNGINX balancerin front - can see detailshereHowever, such an approach may not align with your needs as applications still require this technology to be implemented. In this case, we fully support WebSockets for existing server applications, including:Apache(for providing PHP, Ruby and Python apps) andNGINX(For PHP and Ruby apps)

The WebSockets integration process can vary from application to application. But for server-side setup, Jelastic has provided example configurations for each node mentioned above. So you can uncomment and make minor changes to your application's requirements (such as the listening port number).

Creating the Environment and Deploying Applications

1. Click the buttonNew EnvironmentTop left of dashboard

Ruk-Com Cloud PaaS procedure screenshot

2. Within the Environment Wizard window that appears, switch to the Language tab and select your desired server application. (Take the Apache PHP application for example.) Then scroll through the cloudlets to set the number of resources. Name your environment and clickCreate

3. Within a few minutes your environment will appear in the dashboard.

4. Upload and deploy your application to Deployment Manager or via GIT/SVN remote repository (you can find more instructions atdeployment manual)

Projects that you have deployed are listed at the bottom of the environment panel.

Server and application configuration

WebSockets within the Apache server support module.proxy_wstunnel_moduleThis is added by default when creating a server. For NGINX servers, it uses the ability to embed a proxy. WebSockets connections are similar to how NGINX-balancer does, so let's start configuring your application following this procedure.

1. Click the buttonConfignext to your app server node.

2. In the tabConfiguration ManagerFollow these steps:

  • forApache app server

Go into the directoryconfthen find the filehttpd.confUncomment the command below. (around line 962)

<Location /ws>
   ProxyPass ws://127.0.0.1:<PORT>
   ProxyPassReverse ws://127.0.0.1:<PORT>
</Location>

Then change both parameters to the port number that your WebSockets application listens on (e.g. 9000).

Make sure you have the same configuration as this picture.

Press the buttonSaveabove to save

  • For NGINX app server

Go into the directoryconfSelect filenginx.confthen search#Websocketand uncomment the following command:

upstream websocket {
    server 127.0.0.1:<PORT>;
 }
…
location /ws {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

Then replace the value<PORT>with the corresponding port number and press the buttonSave

3. This is all the server configuration you need to do. Then configure the application you deploy by going into your application's configuration file to set up WebSockets and adjusting the ws path contained in the file according to the next format:

ws://{env_domain}{path_to_ws_file}

where

  • {env_url}Replace with the domain of your environment (can be found under the environment name on the dashboard).
  • {path_to_ws_file}It is required to redirect to a file which should be accessible when the WebSockets connection is established.

4.SaveandRestartYour application server

5. After the restart is complete, click the button.Open in Browserto run your application in a new browser tab.

6. You will see that the application is now working.

You will benefit from significantly faster message transfers by using the WebSockets Protocol.