简体   繁体   中英

My web application does not work when trying to access it by the domain name, but it works if I use the server's IP followed by a port

Disclaimer: This is my first time working with node.js, web servers and web applications all together.

Hey everyone,

I've uploaded my first node.js application to my DigitalOcean droplet (vps). Using Putty I managed to access my server and with a terminal I downloaded NPM , Node , MongoDB , Python and finally Nodemon .

I installed all my dependencies using npm and I was able to start my server using "nodemon app.js". Then, I successfully connected to my web app using the IP address that DigitalOcean provided me for my server.

However, the url auto filled the IP to have :3000 as the port, example: http://123.45.678.999:3000 . Then, I purchased a domain name from GoDaddy, and set the nameservers to ns1.digitalocean.com , ns2.digitalocean.com and ns3.digitalocean.com . On Digital ocean I configured the Networking / DNS settings to link my new domain name to my server's IP.

However, when I navigate to my domain name, my web page simply says :

This page isn't working, domain didn't send any data, ERR_EMPTY_RESPONSE.

I can still connect to my web app using the ip:port.

Am I missing something here? Every guide / tutorial im seeing, people are able to connect using ONLY the IP, why is mine requireing a port? Any Ideas why the domain isnt working? Any help would be greatly appreciated...

Thanks in advance!

When you enter an IP into the browser without any port, it assumes that you entered the port 80, if you use http. So when port is not explicitly written in the browser, port 80 is used. I think you should try to run your node app on port 80 (probably from root user).

It is recommended to use a reverse proxy like nginx for your nodejs application:

https://medium.com/intrinsic/why-should-i-use-a-reverse-proxy-if-node-js-is-production-ready-5a079408b2ca

This will also make it easier to setup https using letsencrypt afterwards: https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM