【问题标题】:nodejs + socket.io over an apache proxynodejs + socket.io 通过 apache 代理
【发布时间】: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


    【解决方案1】:

    the post you linked 一样,您实际上并没有代理 websocket....

    答案基本完整:

    1. 你需要拥有apache module installed的权利
    2. 按照您链接的帖子中的指导进行操作。 socket.io 的 apache 设置有点复杂,但帖子大多是正确的。如果你累了但它不起作用,可能是你没有安装模块。

    如果这一切对你不起作用,请在推特上联系或评论我的回复:)

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2018-04-16
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多