• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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