I'm creating node.js project now. I've a VPS which ubuntu 16.04 as op system and nginx as http server installed on it. As you know we use URL with port number like http://localhost.com:3000 to access our node.js projects. I wonder is there any way to access without port number like http://localhost.com like normal php and other projects?
Asked
Active
Viewed 2,264 times
2 Answers
1
Solution 1
Use Apache or Nginx as a reverse proxy.
Solution 2
Forward port 80 to port 3000 with iptables
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
References:

Hendry
- 882
- 1
- 11
- 27
-
If these links stop working, your answer will no longer function as informative. Please provide relevant information directly in your answer. – Patrick Roberts Mar 22 '18 at 14:08
-
@PatrickRoberts added info for solution 2. For solution 1 it doesn't seem smart to copy all the steps how to set up reverse proxy – Hendry Mar 22 '18 at 14:20
0
The only reason we use those kinds of port numbers for local development is because ports under 1024 are "reserved" and require root permissions to be used. You can still use port 80 for local development if you set your node server to listen on this port.
If you do make these changes to your node server, in order to run it locally you will need to run it as root or using sudo
.

Lix
- 47,311
- 12
- 103
- 131
-
There are better ways that using sudo to run on port 80 https://www.digitalocean.com/community/questions/how-can-i-get-node-js-to-listen-on-port-80 – Hendry Mar 22 '18 at 14:02
-
@Hendry - that's quite a lot of work just to get it serving on port 80 for local development. I don't see any real reason not to run on a different port. As long as we are talking about local development or testing, I feel that using sudo in order to listen on port 80 is not such an issue. – Lix Mar 22 '18 at 14:03
-
-
The question wasn't about local development. But you are right for local development sudo is nice. – Hendry Mar 22 '18 at 14:06
-
@Hendry - I suppose when the OP asked how to access `http://localhost` I understood that we are talking about local development. Especially since we're referencing port 3000 - sounds like a dev environment to me :) – Lix Mar 22 '18 at 14:11
-
2seems like the question needs some improvements, they are also talking about a vps with ubuntu which seems like a testing/prod environment. + http://localhost.com seems like a funny url ;) – Hendry Mar 22 '18 at 14:13