Pointing my domain to my node.js instance

I have a server running whm / cpanel, and I recently experimented with node.js. I have a small node test server, and I would like to point the domain to it. So far I have used whm to create accounts and process domains, but this is a different scenario, and I have little knowledge on how to make a domain point something on my server, when there are several other domains pointing to other different things on my server at the same time.

thanks

0
source share
3 answers

Well, I never tried this, but you could use the rewrite rule in the .htaccess file and rewrite everything to go to port 8000 where your node.js server is running.

So, first configure the node.js server to listen on port 8000.

Then create your domain as normal in cpanel, and in the doc root add a .htaccess file with this rewrite:

RewriteRule ^ "\ http: \ / \ / 127.0.0.1 \:% (8000) REQUEST_URI" [P, QSA, L] 

This should just move everything inside to port 8000, where node.js will take care of that. But I don't know how persistent / websockets will work with this strategy. It is better to skip apache in these cases by going directly to port 8000 on your server.

Source: http://es.w3support.net/index.php?db=sf&id=59994

+1
source

This is a bit complicated, since cpanel is going to use apache to configure domains, and apache has already accepted port 80 without a doubt, so you cannot share port 80 between apache and node.js. You cannot configure this through cpanel.

You can just point the domain to your server and node listen on another port, for example 8000.

Then go to http://mydomain.com:8000/

So, apache / cpanel processes requests to ports 80 and 443, and node processes requests to port 8000.

You can run several web servers in one window, but each of them needs its own port (s)

0
source

I managed to do it like this:

 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} !^3000$ RewriteRule ^ http://%{HTTP_HOST}:3000%{REQUEST_URI} [P,QSA,L] </IfModule> 

Nothing worked for me :(

Here I check if the port is not 3000, and if the protocol is not https, then I point the domain to port 3000 (you can put the port that you use with node.js), you can remove RewriteCond %{HTTPS} !=on in if you do not want to check the protocol.

I do R & D locally, but in production, I suppose that instead of nache, instead of nachex I will use nginx + node.

0
source

All Articles