Skip to content

Instantly share code, notes, and snippets.

@hacheraw
Last active February 12, 2023 02:10
Show Gist options
  • Save hacheraw/960e355218aae6094f4b4f9aca01fd4c to your computer and use it in GitHub Desktop.
Save hacheraw/960e355218aae6094f4b4f9aca01fd4c to your computer and use it in GitHub Desktop.

NodeJS + Plesk + nginx + HTTPS (wss://)

Connecting to a WebSocket server via WebSocket Secure connection (wss://) on a Plesk based host.

Create a subfolder or subdomain

As I'm going to have only one NodeJS, I prefer a subdomain: sockets.example.com If you will have several NodeJS Apps you may want something like example.com/socket1, example.com/socket2, ...

Optional: disable PHP

As I will only use NodeJS on that subdomain, and I will redirect all traffic to NodeJS, it is safe to disable PHP

Apache & nginx Settings

Disable Proxy mode

Turn that option off to stop using Apache

Add additional nginx directives

location / {
	proxy_pass http://127.0.0.1:3000;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
}

Profit

Now you can run your NodeJS (on port 3000 for the above example)

@hacheraw
Copy link
Author

You can also use Plesk's Node.js extension

This way you do not have to add additional nginx directives but you still have to disable proxy mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment