• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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