简体   繁体   English

我的 Web 应用程序在尝试通过域名访问时不起作用,但如果我使用服务器的 IP 后跟一个端口,它就可以工作

[英]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.免责声明:这是我第一次同时使用 node.js、Web 服务器和 Web 应用程序。

Hey everyone,嘿大家,

I've uploaded my first node.js application to my DigitalOcean droplet (vps).我已经将我的第一个 node.js 应用程序上传到我的 DigitalOcean droplet (vps)。 Using Putty I managed to access my server and with a terminal I downloaded NPM , Node , MongoDB , Python and finally Nodemon .使用 Putty,我设法访问了我的服务器,并使用终端下载了NPMNodeMongoDBPython和最后的Nodemon

I installed all my dependencies using npm and I was able to start my server using "nodemon app.js".我使用npm安装了所有依赖项,并且能够使用“nodemon app.js”启动我的服务器。 Then, I successfully connected to my web app using the IP address that DigitalOcean provided me for my server.然后,我使用 DigitalOcean 为我的服务器提供的 IP 地址成功连接到我的网络应用程序。

However, the url auto filled the IP to have :3000 as the port, example: http://123.45.678.999:3000 .但是,url 自动填充 IP 以将 :3000 作为端口,例如: 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 .然后,我从 GoDaddy 购买了一个域名,并将名称服务器设置为ns1.digitalocean.comns2.digitalocean.comns3.digitalocean.com On Digital ocean I configured the Networking / DNS settings to link my new domain name to my server's IP.在数字海洋上,我配置了网络/DNS 设置以将我的新域名链接到我服务器的 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.此页面无效,域未发送任何数据,ERR_EMPTY_RESPONSE。

I can still connect to my web app using the ip:port.我仍然可以使用 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?我看到的每个指南/教程,人们只能使用 IP 进行连接,为什么我的需要端口? 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.当您在没有任何端口的情况下在浏览器中输入 IP 时,如果您使用 http,则假定您输入了端口 80。 So when port is not explicitly written in the browser, port 80 is used.因此,当浏览器中未明确写入端口时,将使用端口 80。 I think you should try to run your node app on port 80 (probably from root user).我认为您应该尝试在端口 80(可能来自 root 用户)上运行您的节点应用程序。

It is recommended to use a reverse proxy like nginx for your nodejs application:建议为您的 nodejs 应用程序使用像 nginx 这样的反向代理:

https://medium.com/intrinsic/why-should-i-use-a-reverse-proxy-if-node-js-is-production-ready-5a079408b2ca 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这也将使之后使用 letencrypt 设置 https 变得更容易: https ://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用服务器域名从本地计算机访问我的nodejs Web服务器? - How can I access my nodejs web server from my local computer using the server domain name? 在IP和端口下而不是域名下托管服务器的Nginx配置 - Nginx configuration for hosting server under ip and port instead of domain name app.use(morgan(“dev”)) 不工作,我的中间件在 app.js 中编写时可以工作,而在 server.js 中编写时它不起作用 - app.use(morgan(“dev”)) Not working, my middleware works when I write it in app.js and it does not work when I write it in server.js 当我点击 https://<external ip> , 我希望能够访问在 GEC 中容器的 3000 端口上运行的应用程序</external> - When I hit https://<external IP>, I want to be able to access the application running on port 3000 on the container in GEC 服务器可以在localhost上运行,但不能在端口80上使用ip - Server works on localhost but not with ip on port 80 在托管程序中将我的域重定向到我的 vps 服务器不起作用 - redirect my domain to my vps server in hostinger does not work 将互联网域名指向套接字流应用程序/端口 - Point internet domain name to socketstream application/port 将域重定向到IP和端口 - Redirect a domain to a ip and port 我的 node.js 服务器的域名是什么? - What's the domain name of my node.js server? 将我的域名重定向到特定端口 - Redirect my domain name to specific port
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM