How to Install a Node.Js Server at Chat.Mydomain.Com on a Hostgator Vps Hosting

how to install a node.js server at chat.mydomain.com on a hostgator vps hosting?

All you need to is to open up a port to listen to requests e.g. if you want to run Node on 8088 and then access it with chat.mydomain.com.

According to their support, you need to contact them to open up 8088 for you > http://support.hostgator.com/articles/pre-sales-policies/open-new-ports

How to set up node.js and socket.io based application on Hostgator VPS

That question is quite long to answer. First you might need to run you app as a service as answered here: Running Node from hostgator's vps

And since port 80 is blocked you'll need to open a new port which is described here: how to install a node.js server at chat.mydomain.com on a hostgator vps hosting?

Then if you don't want your chat application to be accessed solely from a port you can install nginx to access it through a subdomain. You should start by reading here though: http://forums.hostgator.com/adding-nginx-vps-t93880.html

I asked a very similar question 3 years ago which you can read here: hostgator vps level 1 & node.js
This lead me to leave hostgator and move to digitalocean for all my node.js apps. Its a bliss and very quick to get all that you asked for up and running!

Hosting node.js for a specific domain only on a VPS

Follow these steps

  1. Goto "WHM >> Service Configuration >> Apache Configuration >> Reserved IPs Editor" and then 'Reserved' the IP that you want to use for node.js. This will release the IP from apache.

  2. Create a new DNS entry with a A entry like - example.com A YOUR_IP_ADDRESS

  3. Tell the node.js server to listen to your IP using server.listen(80, "YOUR_IP_ADDRESS");

Run node.js on cpanel hosting server

cPanel typically runs Apache or another web server that is shared among all the cPanel/unix accounts. The web server listens on port 80. Depending on the domain name in the requested URL, the web server uses "Virtual Hosting" to figure out which cPanel/unix account should process the request, i.e. in which home directory to find the files to serve and scripts to run. If the URL only contains an IP address, cPanel has to default to one of cPanel accounts.

Ordinarily, without root access, a job run by a cPanel account cannot listen on port 80. Indeed, the available ports might be quite restrictive. If 8080 doesn't work, you might try 60000. To access a running node.js server, you'll need to have the port number it's listening on. Since that is the only job listening on that port on that server, you should be able to point your browser to the domain name of any of the cPanel accounts or even the IP address of the server, adding the port number to the URL. But, it's typical to use the domain name for the cPanel account running the node.js job, e.g. http://cPanelDomainName.com:60000/ .

Of course port 80 is the default for web services, and relatively few users are familiar with optional port numbers in URLs. To make things easier for users, you can use Apache to "reverse proxy" requests on port 80 to the port that the node.js process is listening on. This can be done using Apache's RewriteRule directive in a configuration or .htaccess file. This reverse proxying of requests arguably has other benefits as well, e.g. Apache may be a more secure, reliable and manageable front-end for facing the public Internet.

Unfortunately, this setup for node.js is not endorsed by all web hosting companies. One hosting company that supports it, even on its inexpensive shared hosting offerings, is A2Hosting.com. They also have a clearly written description of the setup process in their Knowledge Base.

Finally, it's worth noting that the developers of cPanel are working on built-in node.js support. "If all of the stars align we might see this land as soon as version 68," i.e. perhaps early 2018.

References

Apache Virtual Hosting -
http://httpd.apache.org/docs/2.4/vhosts/

Apache RewriteRule Directive - http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

A2Hosting.com Knowledge Base Article on Configuring Node.js - https://www.a2hosting.com/kb/installable-applications/manual-installations/installing-node-js-on-managed-hosting-accounts

cPanel Feature Request Thread for node.js Support - https://features.cpanel.net/topic/nodejs-hosting

Related StackOverflow Questions

How to host a Node.Js application in shared hosting

Why node.js can't run on shared hosting?

Deploy Next.js to Shared Hosting

On the server, you can do like this, and of course you should have pm2 (npm install -g pm2) and config for nginx to proxy pass the port that your next server will run, e.g 6060 (add to nginx.conf/server/location this line: proxy_pass http://localhost:6060) and then:

  1. upload source folder (pages, public, src , package.json) - e.g your-folder to somewhere
    like /var/www/your-folder
  2. chown it: sudo chown -R $USER:$USER /var/www/your-folder
  3. cd to your-folder and run:
    npm -i
  4. then edit package.json and change "next start -p your-port" e.g 6060
  5. npm run build
  6. run pm2 (in your-folder) : pm2 start "npm run start" --name project-whatever-you-like

For pm2 to auto-restart you run: pm2 startup systemd , pm2 will produce a line and you should copy that line and run it.

On shared hosting there's a lot providers now support running nodejs app, but I dont know if they can run nextjs app, e.g in plesk you can config to run nodejs app by configuring app.js path and project folder path, public folder path etc, but for next app, you dont have an app.js to run, but a script to start next server. Anyway you can try :)

Or you can simply move to a vps, its price is now rather bargain, and you can do a lot of things with your own server (Google Compute Engine is giving free stuff - almost free for a year)



Related Topics



Leave a reply



Submit