简体   繁体   English

Apache 代理到 websocket 服务器不起作用

[英]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.所以我试图让我的 websocket 服务器升级到 HTTPS,但我遇到了一些麻烦。 The server itself worked before I started kerfufling around with SSL&Co.在我开始使用 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. websocket服务器是用node写的,只服务websocket,前端服务器是Apache,服务客户端应用。

The WebSocket side (basically) is: 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"});

and the Apache virtualhost is和 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>

A test client has the following line: ws = new WebSocket("wss://dev.domain/ws");测试客户端具有以下行: 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 .并且当该线路被触发时,Chrome 表示WebSocket connection to 'wss://dev.domain/ws' failed: Error during WebSocket handshake: Unexpected response code: 404的威胁性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.没有任何行打印到 apache 错误日志中。

Thank you for your help!感谢您的帮助!

What happens if you use:如果您使用会发生什么:

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

That is, matching trailing '/'s也就是说,匹配尾随 '/'s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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