[英]Running socket.io on Shared Hosting
I am using a shared hosting server from A2Hosting where I want to run a socket.io server (application), here is what I have done so far:我正在使用来自 A2Hosting 的共享托管服务器,我想在其中运行 socket.io 服务器(应用程序),这是我到目前为止所做的:
var server = require('http').createServer(),
io = require('socket.io')(server),
port = 58082;
server.listen(port, my - domain - name);
But my client (the browser) can't connect to the server.但是我的客户端(浏览器)无法连接到服务器。
I have tried running the same socket.io sever (application) on a local Linux machine and I was able to successfully connect via the browser, so the issue lies in the configuration of the shared hosting server.我尝试在本地 Linux 机器上运行相同的 socket.io 服务器(应用程序),并且我能够通过浏览器成功连接,所以问题在于共享托管服务器的配置。
You're almost there.你快到了。 The one thing missing is the integration of your socket.io application with the webserver.缺少的一件事是您的 socket.io 应用程序与网络服务器的集成。 For that you will need a .htaccess
file to redirect the incoming requests.为此,您需要一个.htaccess
文件来重定向传入的请求。
Create a .htaccess
file in the public_html
directory and add the snippet below.在public_html
目录中创建一个.htaccess
文件并添加下面的代码段。 Replace the XXXXX
with an unused port anywhere between 49152
and 65535
, those are the ones available.将XXXXX
替换为49152
和65535
之间任何未使用的端口,这些是可用的。 If your application won't start, try a different port.如果您的应用程序无法启动,请尝试其他端口。
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:XXXXX/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:XXXXX/$1 [P,L]
If you need a more detailed guide / sources:如果您需要更详细的指南/来源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.