• 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

Resolved Nginx WebSocket Connection as Secure Problem

someonefromspace

New Pleskian
hi everyone;

I setup a websocket connection on my host, i can connect it and use as well, no problem on http:// schema. See: Screenshot (it's okay).

Code:
var conn     = new WebSocket('ws://my.domain.com:2001');

But I want to use this connection websocket connection on SSL - https:// schema. At at time, I get connection error like this.

Proxy mode is on: Screenshot

PHP works with NGINX, see: Screenshot

What I tried:
I added this block to /..vhosts/domain.com/mysub.domain.com/conf/nginx/nginx.conf
Code:
 location ~ /WsConn
 {
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_pass https://mysub.domain.com:2001;
 }

Then, I tried to connection on SSL schema,
Code:
var conn     = new WebSocket('wss://my.domain.com/WsConn');
Code:
var conn     = new WebSocket('ws://my.domain.com/WsConn');

they don't work. the last error which i got: Screenshot

What could be solution?? and thank you.
 
And when you connect directly to wss://mysub.domain.com:2001, does it work? Did you configure that backend to use SSL? (Reminder that you can only use unencrypted or SSL on each port, sharing is only possible with STARTTLS which does not help here.)
If you wanted to use nginx to add SSL to the websocket because it can not use SSL on its own, then the connection from nginx to the backend must use http, not https, i.e.
NGINX:
proxy_pass http://mysub.domain.com:2001;
 
And when you connect directly to wss://mysub.domain.com:2001, does it work? Did you configure that backend to use SSL? (Reminder that you can only use unencrypted or SSL on each port, sharing is only possible with STARTTLS which does not help here.)
If you wanted to use nginx to add SSL to the websocket because it can not use SSL on its own, then the connection from nginx to the backend must use http, not https, i.e.
NGINX:
proxy_pass http://mysub.domain.com:2001;

  • - ''when you connect directly to wss://mysub.domain.com:2001, does it work?''
    + yeap, it does not work.

  • and yes, domain has an SSL connection, it works well as https:// schema.

  • - ''If you wanted to use nginx to add SSL to the websocket because it can not use SSL on its own, then the connection from nginx to the backend must use http, not https, i.e.''
    + hmm maybe I, missed it, don't remebber.

fortunately, I solved this issue like that:

  • Go to Plesk Admin, my domain hosting settings -> Apache & nginx Settings
  • Paste this block to Additional Nginx Directives:
Code:
location ~ /WsConn
{
    proxy_pass             http://127.0.0.1:2001;
    proxy_read_timeout     60;
    proxy_connect_timeout  60;
    proxy_redirect         off;
    
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

maybe it helps to someone.

thank you for your answer.
 
  • - ''when you connect directly to wss://mysub.domain.com:2001, does it work?''
    + yeap, it does not work.

  • and yes, domain has an SSL connection, it works well as https:// schema.

  • - ''If you wanted to use nginx to add SSL to the websocket because it can not use SSL on its own, then the connection from nginx to the backend must use http, not https, i.e.''
    + hmm maybe I, missed it, don't remebber.

fortunately, I solved this issue like that:

  • Go to Plesk Admin, my domain hosting settings -> Apache & nginx Settings
  • Paste this block to Additional Nginx Directives:
Code:
location ~ /WsConn
{
    proxy_pass             http://127.0.0.1:2001;
    proxy_read_timeout     60;
    proxy_connect_timeout  60;
    proxy_redirect         off;
   
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

maybe it helps to someone.

thank you for your answer.
Thank you so much it did help me after hours of search
 
Back
Top