• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue Phusion Passenger WebSockets handshake issue

Edi Duluman

Basic Pleskian
Hello!

Few weeks ago, on the Plesk Facebook Page, there was a tutorial on how to install and run nodeJS applications.

I running applications, logging and debugging, everything working as expected.
Only issue now is that I have apps which of course, require socket.io, therefore I have set it up, ran it and works smoothly.

Problem is that, when I try connecting to the server, I get an
Error during WebSocket handshake: Unexpected response code: 400

You can test it out here: http://frisk.duluman.ro/a.html

Same code, connecting to the same node app, but another server, pure nodejs / socket.io install with no Plesk on it: http://frisk.duluman.ro/b.html

I found something regarding the Nginx Proxy here: https://github.com/socketio/socket.io/issues/1942#issuecomment-82352072

But I can't apply those settings in Apache & Nginx settings in Plesk due the duplicate location / test fail.

This is the app.js file, dead simple.

upload_2016-8-16_11-45-28.png

Anyone having any idea ?

Thanks in advance!
 
Hello!

After some digging, I've seen the only difference in between these two would be the following:

A9RcMJ5.png


Seems like Plesk's Nginx doesn't like the request for some reason and returns a 400 Bad Request back.
Tried checking the logs in /var/log/nginx/error.log, nothing in it regarding these requests.

Any info ? I'm really struggling right here.
 

Attachments

  • upload_2016-8-16_20-14-28.png
    upload_2016-8-16_20-14-28.png
    192.8 KB · Views: 9
Hi Edi Duluman,

pls. be aware, that domain specific errors for apache and nginx are located inside the domain specific errors logs ( example for your case ):

/var/www/vhosts/system/frisk.duluman.ro/logs/

But I can't apply those settings in Apache & Nginx settings in Plesk due the duplicate location / test fail.
If you experience issues/problems/failures, when adding additional nginx directives, pls. consider to modify the directives, so that additional directives don't conflict with existing ones. Pls. have a look at your current configuration files at "/var/www/vhosts/system/frisk.duluman.ro/conf/" to avoid duplicate entries.

You could for example move your application to the folder "app1" an then use the additional nginx directive:
Code:
location /app1 {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
 
We're trying to move from a (working) custom Nginx+Node setup to the Plesk provided one and it's causing all kinds of problems!

Would one of the posters in this thread be kind enough to provide
A simple working (complete) app.js + file placement list + Nginx config

If we have a working example the rest should be easy to solve.

Spending a couple of days digging through forums and S/O isn't the best use of time... I wish Plesk would get their act together with documentation.
 
Hi Edi,

We are on Plesk Onyx - Version 17.0.17 Update #9, last updated on Dec 7, 2016 12:54 AM. Ubuntu 16.04 LTS

It's set up using Apache / Phusion passenger as described in Plesk docs and works for returning standard HTTP if I add a get / route to the app.js

However no matter what I try the proxying and upgrade headers aren't working. Hence looking for some guidance in getting that part working.

Instead of going backwards and forwards troubleshooting individual problems I thought if someone could post a working ws app.js / package.json / nginx config it would be plenty to work backwards from for me and everyone else with this issue.

Thanks for your help!
 
Every kind of app.js will work unless you have some unintended errors in it.

Problem with NodeJS apps ( before plesk onyx ) as you might have found my other threads on github and / or stackoveflow and even here, was that Apache was always part of the request processing, which kind of fails when trying to switch port protocols, 101.

But now with Plesk Onyx, Apache can be "disabled" on per-domain basis.

So if you go to Domains > yourdomain.com > Apache & Nginx settings and untick the "Proxy mode" which states that by disabling it, nginx will no longer proxy requests to apache, which is great.

Now, if you untick that, hit save, go to your nodejs app and restart, everything will be good.

Note that you should be using ExpressJS for routing ( easiest to get along with in my humble opinion ), then use socket.io as a socket client, and initiate the socket io client over the httpServer ( i call it app ) variable generated when initialized the app with ExpressJS, therefore the socket will be
On the same port 80 , as your ( webservice, site or ehatever is that you try to run ).

I'm writijg on mobile so.. excuse the grammar issues. Even so you should have posted in the dedicated section for Plesk Onyx in this forum.

https://frisk.seesnaps.com is a REST API of mine, in NodeJS, and it is also a sovket service, on the same port, if you try connecting to ws://frisk.seesnaps.com

You will get a fail login as you need some credentials, but it validates the point I'm trying to make, as Node apps improved a lot in Plesk onyx.

One thing I noticed though was that you said you configured Apache and phusion passenger.

I need to remind you that Plesk onyx comes with support for nodejs directly ( though its through the same system ) but you have access to node versions, app restart directly from the gui. You just need to rollback what you did and install the NodeJS component from Plesk > Updates & Upgrades > Add components > ( web hosting if i recall correctly ) and look for NodeJS.

Also you should remember that the app's log will be placed in /var/log/nginx/error.log and you should read it via tail -f

Cheers.
 
Back
Top