I hope this doesn't come across as a terribly silly question, but I'm learning how to implement a socket.io server for my website to produce real-time applications, but my problem is that I can't figure out how to implement said applications in an Apache served environment. Currently, when I run node server.js
to start my socket.io server, I have to access it by visiting http://localhost:XXXX
where XXXX
is whatever port I attach it to, naturally. I don't want my website to be forced to be viewed on an alternate port like this, but I obviously can't attach the server to port 80 since Apache is listening on that.
我希望这不是一个非常愚蠢的问题,但我正在学习如何为我的网站实现一个socket.io服务器来生成实时应用程序,但我的问题是我无法弄清楚如何在Apache服务环境中实现所述应用程序。目前,当我运行node server.js来启动我的socket.io服务器时,我必须通过访问http:// localhost:XXXX来访问它,其中XXXX是我附加到它的任何端口,当然。我不希望我的网站被强制在这样的备用端口上查看,但我显然无法将服务器连接到端口80,因为Apache正在监听它。
Obviously a natural solution would be to stop the Apache service and then node the server on port 80 that way to avoid a collision, but I don't want to sacrifice all of the functionality that Apache offers. Basically, I want to continue to serve my website via Apache on port 80, and integrate certain aspects of real-time applications via socket.io on port 3000, let's say.
显然,一个自然的解决方案是停止Apache服务,然后在端口80上节点服务器以避免冲突,但我不想牺牲Apache提供的所有功能。基本上,我想继续通过端口80上的Apache服务我的网站,并通过socket.io在端口3000上集成实时应用程序的某些方面,让我们说。
Is there a way to do this that avoid the things I don't want? Those things being 1) having users access my site with :3000
in the URL, 2) disabling Apache, 3) using iframes.
有没有办法做到这一点,避免我不想要的东西?这些事情是1)让用户访问我的网站:URL中的3000,2)禁用Apache,3)使用iframe。
Thanks in advance.
提前致谢。
2 个解决方案
#1
3
Generally, you should be able to hide Node.js with mod_proxy. A bit of searching turned up this: https://github.com/sindresorhus/guides/blob/master/run-node-server-alongside-apache.md (old link died, this is a new one)
通常,您应该能够使用mod_proxy隐藏Node.js.有点搜索出现了这个:https://github.com/sindresorhus/guides/blob/master/run-node-server-alongside-apache.md(旧链接死了,这是一个新的)
However, Socket.io can be a bit finicky (https://github.com/LearnBoost/socket.io/issues/25), so you may have problems with it specifically.
但是,Socket.io可能有点挑剔(https://github.com/LearnBoost/socket.io/issues/25),所以你可能会遇到问题。
As that ticket is a bit old, it's worth a shot. Just don't be surprised if you have problems. You're next bet after that is bind Node.js toport 80 and have it act as a reverse proxy for Apache with https://github.com/nodejitsu/node-http-proxy (still under a fair bit of development).
由于那张票有点旧,值得一试。如果您遇到问题,请不要感到惊讶。你接下来的赌注是绑定Node.js toport 80并让它作为Apache的反向代理使用https://github.com/nodejitsu/node-http-proxy(仍在开发中)。
The optimal solution would be run it on it's own server and just have you're socket traffic go to socket.example.com or something like that.
最佳解决方案是在它自己的服务器上运行它,然后让你的套接字流量转到socket.example.com或类似的东西。
#2
2
Socket.io has multiple transport mechanisms. Some of them don't work if you run Apache as reverse proxy, but some do. Transports that don't work are websocket and flash, but xhr-polling and jsonp-polling should work.
Socket.io有多种传输机制。如果你运行Apache作为反向代理,它们中的一些不起作用,但有些人会这样做。不起作用的传输是websocket和flash,但xhr-polling和jsonp-polling应该可以工作。
Here's an example on setting the transports configuration option for socket.io:
以下是为socket.io设置传输配置选项的示例:
var io = require("socket.io").listen(server);
io.set("transports", ["xhr-polling", "jsonp-polling"]);
On my Apache I'm using the normal name based virtual hosts and reverse proxy setup and with these transports the socket.io seems to be working.
在我的Apache上我使用基于普通名称的虚拟主机和反向代理设置,并且使用这些传输,socket.io似乎正在工作。
#1
3
Generally, you should be able to hide Node.js with mod_proxy. A bit of searching turned up this: https://github.com/sindresorhus/guides/blob/master/run-node-server-alongside-apache.md (old link died, this is a new one)
通常,您应该能够使用mod_proxy隐藏Node.js.有点搜索出现了这个:https://github.com/sindresorhus/guides/blob/master/run-node-server-alongside-apache.md(旧链接死了,这是一个新的)
However, Socket.io can be a bit finicky (https://github.com/LearnBoost/socket.io/issues/25), so you may have problems with it specifically.
但是,Socket.io可能有点挑剔(https://github.com/LearnBoost/socket.io/issues/25),所以你可能会遇到问题。
As that ticket is a bit old, it's worth a shot. Just don't be surprised if you have problems. You're next bet after that is bind Node.js toport 80 and have it act as a reverse proxy for Apache with https://github.com/nodejitsu/node-http-proxy (still under a fair bit of development).
由于那张票有点旧,值得一试。如果您遇到问题,请不要感到惊讶。你接下来的赌注是绑定Node.js toport 80并让它作为Apache的反向代理使用https://github.com/nodejitsu/node-http-proxy(仍在开发中)。
The optimal solution would be run it on it's own server and just have you're socket traffic go to socket.example.com or something like that.
最佳解决方案是在它自己的服务器上运行它,然后让你的套接字流量转到socket.example.com或类似的东西。
#2
2
Socket.io has multiple transport mechanisms. Some of them don't work if you run Apache as reverse proxy, but some do. Transports that don't work are websocket and flash, but xhr-polling and jsonp-polling should work.
Socket.io有多种传输机制。如果你运行Apache作为反向代理,它们中的一些不起作用,但有些人会这样做。不起作用的传输是websocket和flash,但xhr-polling和jsonp-polling应该可以工作。
Here's an example on setting the transports configuration option for socket.io:
以下是为socket.io设置传输配置选项的示例:
var io = require("socket.io").listen(server);
io.set("transports", ["xhr-polling", "jsonp-polling"]);
On my Apache I'm using the normal name based virtual hosts and reverse proxy setup and with these transports the socket.io seems to be working.
在我的Apache上我使用基于普通名称的虚拟主机和反向代理设置,并且使用这些传输,socket.io似乎正在工作。