Running socket.io on Shared Hosting

你说的曾经没有我的故事 提交于 2020-04-10 06:08:59

问题


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:

  1. SSH'ed into server
  2. Installed node
  3. Run / started the socket.io server (application)
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.


回答1:


You're almost there. The one thing missing is the integration of your socket.io application with the webserver. For that you will need a .htaccess file to redirect the incoming requests.

Create a .htaccess file in the public_html directory and add the snippet below. Replace the XXXXX with an unused port anywhere between 49152 and 65535, those are the ones available. 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:

  • Running a Node.js Application on Shared Hosting
  • How to install and configure Node.js on managed hosting accounts


来源:https://stackoverflow.com/questions/45532690/running-socket-io-on-shared-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!