Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
Does Node.js and Ruby on Plesk support WebSockets (socket.io)?
How to provide WebSockets feature to customers?
Answer
Plesk itself does not forbid to use WebSockets, it only provides runtime environment to run Node.js and Ruby using Phusion Passenger, or iisnode.
The rest depends on particular website code design/implementation details.
Note: Websockets work properly only if nginx-only web hosting is configured (with Proxy mode disabled) due to the following Apache module issue: WebSockets don't work on Apache.
-
Go to Websites & Domains > example.com > Apache & nginx Settings
-
In the nginx settings section, clear the Proxy mode checkbox
Note: In case this checkbox is not present, install, or enable nginx.
-
Click on Apply
-
Navigate to Domains > example.com > File Manager
-
Open the
web.config
file in the application's document root, and add the following configuration to the <system.webServer> section:CONFIG_TEXT: <rewrite>
<rules>
<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io.+" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>Note: In case <rewrite> section already exists in the configuration file, instead add the <rule> part to the existing <rules>
The sample "Phusion Passenger: Node.js WebSocket demo" application can be used to verify whether WebSocket connections are working fine on the webserver: https://github.com/phusion/passenger-nodejs-websocket-demo
Comments
8 comments
I'm getting the below error when trying to save the Additional Apache directives
"Invalid nginx configuration: nginx: [emerg] unknown directive "RewriteEngine" in /var/www/vhosts/system/console.domain.win/conf/vhost_nginx.conf:2 nginx: configuration file /etc/nginx/nginx.conf test failed"
Hi @Generall Omosco!
I was able to get the same error when pasting rewrite rule into the "Additional nginx directives" field.
As mentioned rules are for Apache web server, make sure you paste them in the proper location (meanwhile, it worked for me):

Hi, I have developed an application with web services endpoints and websocket support for live data streaming with Node.js. I've followed everything in your instructions,
enabled the proxy_wstunnel (proxy was already enabled), added the rules for both HTTP and HTTPS and even tried the demo example but to no avail. With my code
I was getting "connection reset by peer". Note that I redirect all the traffic to HTTPS. The HTTP/HTTPS part works OK, only the websockets part fails even with the
demo from Phusion Passenger. Our version is Plesk Onyx 17.8.11 (Update #19). Any ideas what might be wrong?
@George Moralis The example above assumes that the application is already running and listen port 4000. As it was mentioned in the article there are known issues with WebSockets on Apache + Passenger
To get the socket.io application work, just disable "Proxy mode" in "Websites & Domains > Apache & nginx Settings". Additionally, due to passenger specifics, consider using dynamic port server.listen(process.env.PORT) instead of a static port.
Hello, very interesting your tutorial, but I need your help, in my plesk panel I use this code. Because a soft I've, requires to work with ports 3000, but this software app requires that the server also handles WebSockets, because otherwise the app is not working anymore
location ~ / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://chat.shqiperia.chat:3000;
}
What I would like to ask from you is: Is it possible to place a code in Additional nginx directives that can redirect the subdomain to the gates 3000 and handle WebSockets. If anyone is able to do it, I would be very grateful if you could give me some thought,
thanks
@Artur Beqiraj
Such scenario was not tested officially and we have no documented solution for it.
I suggest you address your question on our Forum, there are a lot of specialists that could advise you some solution.
The "Apache / Apache + nginx" didn't work out for me.. The Error 400 during WebSocket handshake went to either a 502 Bad Gateway or 503 Service temporary unavailable error. I then went ahead and created a sub-domain and applied the "Nginx-Only Hosting" solution to that. Like magic it worked. :)
Hello @ArendE,
>> The Error 400 during WebSocket handshake went to either a 502 Bad Gateway or 503 Service temporary unavailable error
Please make sure that WebSockets application is already running and listen port 4000.
As it was mentioned in the article there are known issues with WebSockets on Apache + Phusion Passenger
It is recommended to use Nginx-Only Hosting solution for WebSockets.
Please sign in to leave a comment.