Apache代理到websocket服务器无法正常工作

时间:2017-10-02 18:30:48

标签: node.js apache ssl websocket

所以我试图让我的websocket服务器升级到HTTPS并且我遇到了一些麻烦。在我开始使用SSL& Co之前,服务器本身就已经工作了。 websocket服务器是在节点中编写的,只提供websocket,前端服务器是Apache,并为客户端应用程序提供服务。

WebSocket方面(基本上)是:

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"});

和Apache虚拟主机是

<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>

测试客户端具有以下行:ws = new WebSocket("wss://dev.domain/ws");,当该行被触发时,Chrome会发出威胁WebSocket connection to 'wss://dev.domain/ws' failed: Error during WebSocket handshake: Unexpected response code: 404。没有行打印到apache错误日志。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

使用时会发生什么:

  

ProxyPass&#34; wss:// localhost:36245 / ws /

即匹配尾随&#39;