How to access node.js site with direct url without mentioning port 8080 in aws ubuntu, Apache2 - node.js

My node.js application is running on port 8080. I want to access it via url without mentioning port number in the URL. How will i achieve this?
for example :
current : www.domainname.com:8080
Expected :www.domainname.com
Ubuntu os version: 16
Server : Apache2
Need help.

Use Nginx as a reverse proxy for your node js application and mentioned your port in nginx config file.(you can create new config file or you can use default one /etc/nginx/nginx.conf)
Install pm2 and Use pm2 tool to keep running your nodejs application in the background.
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs
sudo npm install pm2#latest -g
pm2 start myapp.config.js (replace myapp.config.js with YOURAPP.js )

Related

run npm start with sudo doesn't allow access port 80

I have a EC2 running instance from AWS and I tried to run my node server on port 80 using sudo npm start which is just running script node ./bin/www but it crashed and telling me port 80 requires elevated privileges. It was fine if I just do sudo node ./bin/www. I am not sure why and it seems the npm just doesn't accept my sudo.
I tried to run npm start as a root user and it still wouldn't let me to access port 80.

Deploy node.js in hostinger VPS but not running

I have my node app upload into hostinger and npm start run well.
But I still can't access http://my-ip:3000
node and npm and mysql have been installed
but no luck.
Am I missing some important steps?
this problem could come from your code || network
pm2 logs
see if there are some error logs
check on vps that if your service online
curl http://127.0.0.1:3000
if no resposne, you should fix the service code
check if your service runs on the right port
netstat -an | grep 3000

host public node js website on amazon AWS LightSail without Bitnami

I have an amazon AWS LightSail instance and have installed Node js downloaded from nodejs.org. Now the setup is complete and I am able to launch my nodejs webpage inside LightSail instance using "http://localhost but when I try to do it using the lightsail public IP from any other laptop, it not getting accessible (getting web error as "This site can’t be reached").
I have set the node js to listen to port 80 which is open by default.
A lot of materials shows that bitnami as a way to do it but can't I use normal node js installation to make the website public. Appreciate any guidance on this
Bitnami Engineer here,
You can configure your Nodejs app to use the port 3000 and then configure Apache to ProxyPass the requests to that port. This way you will be able to access your app using http and https. Does that sound good? You will need to run these commands:
Create the folders
sudo mkdir -p /opt/bitnami/apps/myapp
sudo mkdir /opt/bitnami/apps/myapp/conf
sudo mkdir /opt/bitnami/apps/myapp/htdocs
Create a /opt/bitnami/apps/myapp/conf/httpd-prefix.conf file with this content
Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
Add this content to the /opt/bitnami/apps/myapp/conf/httpd-app.conf file
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
Add this line to the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file
Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
Restart Apache
sudo /opt/bitnami/ctlscript.sh restart apache
You have more information in our documentation
https://docs.bitnami.com/aws/infrastructure/nodejs/administration/create-custom-application-nodejs/

Getting 404 on sails project when reaching through machine name

I am pretty new to sails module on node.js
I created a basic web-app and it launches good on
http://localhost:8081/test
but when I try to access with my machine name like
http://mymachinename:8081/test
it goes 404 page. I also tried to access from another PC in same domain and same 404 error.
I expect both requests should return 200 response.
Am I missing something?
Here is a little information and some suggestions. Here I am on MAC OS X.
First, yes it should work out of the box:
$ sails new app && cd $_ && npm install
$ sails lift --port 1338
http://127.0.0.1:1338/
http://192.168.0.5:1338/
http://mymachine.local:1338/
are all equivalent (loopback, my local IP, my local machine name respectively).
Try a port scan and see if the port you think it is running on is actually running or else already occupied.
On Mac OS X.
lsof -i :1337
Perhaps try starting on a different port:
sails lift --port 1338 (i did this for the above)
Did you install sails globally? If so, you could try uninstalling and reinstalling:
npm uninstall -g sails
npm install -g sails
If you are still having problems, they are local and very unlikely specific to SailsJS. Do usual troubleshooting for network / port related issues locally etc.
Finally, to gain access for other users to your local machine, i usually use ngrok. Ngrok exposes your localhost to the web - example:
$ npm install ngrok -g
$ ngrok http 1338
See this example usage:
In the above example, the locally running instance of sails at: localhost:1338 is now available on the Internet served at: http://840fa6c4.ngrok.io

Application generating "Error: listen EACCES" while starting application with pm2 on port 80?

We are using pm2 for starting my nodejs app on port 80 on ubuntu. But the application generating error **Error: listen EACCES**. Our pm2 version is 0.12.7 and we are using the following command:
sudo pm2 start app.js -- dev
On running whereis node we get the following result:
node: /usr/bin/node /usr/sbin/node
We have already tried following commands:
sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/local/sbin/node
Any idea where are we going wrong?
Sounds like you might have another service already listening on port 80. try this:
sudo netstat -tulpn
The output of this will tell you if any other process is currently using port 80.

Resources