Score:0

Proxy pass to express http server not working with secure websocket

cn flag

So I currently have apache with a proxy pass which redirects all requests to an express api running using the http node module, I also have a letsencrypt ssl certificate installed and all is working fine on this part. However, When I try to open a secure websocket connection it errors. I have only the bare minimum experience as far as apache configuration and ssl configuration goes so please bare with me.

On my server:
server.ts

import * as http from 'http';
import * as Websocket from 'ws';
import * as express from 'express';
...
const app = express();
const server = http.createServer(app);
const wss = new Websocket.Server({ server, path: '/ws' });
...
server.listen(3005, () => {
    console.log('Server started on port 3005');
});

On the browser:
index.js

const ws = new WebSocket('wss://mydomain.tld/ws');

And my apache config file for the domain
mydomain.tld.conf

<VirtualHost *:443>
    ServerName mydomain.tld
    ProxyPreserveHost On

    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://127.0.0.1:3005/ retry=0
    ProxyPassReverse / http://127.0.0.1:3005/
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.tld
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

So again to quickly sum up the issue, I can create successful ssl secured https requests but not websocket requests to the server. Thanks in advance.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.