简体   繁体   中英

Apache proxy to websocket server not working

So I'm trying to get my websocket server upgraded to HTTPS and I'm having some trouble. The server itself worked before I started kerfufling around with SSL&Co. The websocket server is written in node and serves only the websocket, the front facing server is Apache and serves the client application.

The WebSocket side (basically) is:

const websock = require('./node_modules/ws');
const fs = require('fs');

console.log("Starting VoxelatedAvacado server.");
const server = require('https').createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/domain/cert.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/domain/privkey.pem'),
    port: 36245
});
const wss = new websock.Server({ server: server, path: "/ws"});

and the Apache virtualhost is

<VirtualHost *:443>
ServerName dev.domain
DocumentRoot /var/www/domain/client_dev

    <Directory /var/www/domain/client_dev/>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    CustomLog ${APACHE_LOG_DIR}/access.log common_complete

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml $
    </IfModule>

SSLEngine on
SSLProxyEngine on
SSLCertificateFile /etc/letsencrypt/live/domain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/domain/fullchain.pem

<Location "/ws/">
    ProxyPass "wss://localhost:36245/ws"
</Location>

<FilesMatch "\.(cgi|shtml|phtml_php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
</VirtualHost>

A test client has the following line: ws = new WebSocket("wss://dev.domain/ws"); and when the line is triggered Chrome says a menacing WebSocket connection to 'wss://dev.domain/ws' failed: Error during WebSocket handshake: Unexpected response code: 404 . No lines are printed to the apache error log.

Thank you for your help!

What happens if you use:

ProxyPass "wss://localhost:36245/ws/

That is, matching trailing '/'s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM