Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting Nodejs application without port

I have a nodejs application running on port 3000. I wanted to host it on Linux environment. So I installed nodejs in it. It's working fine but I should specify the port each time.

example: mydomain.net:3000/url_i_want,

How can I avoid this. and also when running my app like that, all users are kind of connected to each others. If one of them disconnect all other users are. If one of them change page all others have there pages changing. Is it because they are all listening to the same port 3000 ? I searched and found that it can be related to PM2 and Nginx. Is it the solution ?

like image 696
Meryam Avatar asked Jan 05 '23 21:01

Meryam


1 Answers

Whenever you load a URL without specifying the port number, the browser defaults to 80, because 80 is the default port number for HTTP.

So if you load http://stackoverflow.com/questions, the browser "converts" it to http://stackoverflow.com:80/questions.

If you don't want a port number to be specified to access your website, your app should be listening on port 80, instead of 3000.

However, it is not recommended for Node apps to directly listen on port 80 (although they very well can).

What you can do is use a front-facing proxy such as nginx, which accepts connections to the host's port 80, and then redirects the request to localhost:3000, where your app is listening.

It is best to ask one question at a time.

As for your second question, unless you are using some sort of "remote syncing" framework, that sort of behavior is unexpected. I would suggest posting a separate question for that issue with more details about it.

like image 155
Hage Yaapa Avatar answered Jan 07 '23 12:01

Hage Yaapa