【发布时间】:2021-03-04 12:27:12
【问题描述】:
一段时间以来,我一直在尝试让 nodejs / socket.io 服务器在 Apache (2.4) 反向代理上工作。该服务器在我的本地和没有代理的 Apache 上运行良好。它也适用于 without socket.io 的反向代理。所以我认为我主要是在使用 socket/io 代理配置时遇到问题。我已经尝试了很多很多东西(issues running socket.io over an apache proxyRunning Socket.io over Apache Reverse Proxyhttps://github.com/socketio/socket.io/issues/1696),但都没有奏效,很可能是因为我对代理重定向和 socket.io 的理解很浅。这是我的文件的最新配置(简化):
server.js(在 /nodejs 中)
var serverPort =3003
var http = require('http');
var fs = require('fs');
var server = http.createServer(function (req, res) {
fs.readFile('index.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
return res.end();
});
});
var io = require('socket.io')(server);
server.listen(serverPort, '127.0.0.1');
io.on('connection', function(socket) {
console.log('new connection');
socket.emit('message', 'This is a message from the dark side.');
});
index.html(在 /nodejs 中)
<script src="/socket.io/socket.io.js"></script>
var socket = io.connect();
socket.on('message', function(data) {
alert(data);
});
这给出了一些问题,因为无法访问 socket.io.js 文件(第一行),当通过直接链接提供时,问题出现在连接部分(因为它无法到达服务器端) .
这里是。我认为相关的 https.conf 文件:
<VirtualHost xx.xx.xx.xx:443>
<Proxy balancer://mongrel3003>
BalancerMember http://localhost:3003
</Proxy>
ProxyPass /nodejs balancer://mongrel3003
ProxyPass /socket.io balancer://mongrel3003
ProxyPassReverse /nodejs balancer://mongrel3003
ProxyPassReverse /socket.io balancer://mongrel3003
</VirtualHost>
非常感谢任何帮助。谢谢
【问题讨论】:
标签: node.js apache socket.io proxy