在我的机器上托管节点应用程序 [英] Hosting Node app on my machine

查看:71
本文介绍了在我的机器上托管节点应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个节点应用程序,我可以通过localhost访问:someportnumber。如何仅使用我的机器而不是某种托管服务公开地公开这个应用程序(即,到interwebz的其余部分,而不仅仅是我的本地网络)。 Machine是一个macbook pro,不确定它是否重要。



注意 - 这纯粹是为了理解,我不打算在我的笔记本电脑上永久托管玩具webapp。 / p>

这是我的困惑 - 我的node.js应用程序是一个WEBSERVER,为什么我需要另一台服务器(即由heroku,aws等提供的服务器)来托管我的应用程序吗?我觉得我错过了什么...

解决方案

假设这是一个家庭网络,那么你很可能有一些路由器/防火墙将您的家庭网络连接到互联网。默认情况下,路由器阻止所有到网络的传入连接(出于安全原因)。



如果需要,您可以设置所谓的端口转发规则您希望端口80上的任何传入连接(来自浏览器的默认HTTP端口)的路由器直接路由到您的家庭网络上的macbook pro。通常,您可以通过在家庭网络上发现Macbook pro的IP地址来实现这一点,并将端口转发规则设置为该IP地址。端口转发规则通常通过某种基于Web的管理员用户界面进行配置,您可以在Web浏览器中使用该界面。您必须查看特定路由器的手册,以了解如何最好地连接到它并进行配置。



除非您将macbook pro设置为具有静态IP地址,其IP地址将由路由器动态分配。它可能会暂时保持不变,但可能会随着时间的推移而改变。



完成此操作后,您需要发现家中的IP地址网络连接。这可能也会动态分配,但也应保持一段时间。你知道这个IP地址,然后浏览器上的浏览器可以通过URL http://xxx.yyy.zzz 连接到你的网络服务器,其中 xxx.yyy.zzz 是从互联网上看到的家庭网络的IP地址。



如果你想能够使用普通域名(例如 http://mysampledomain.com )连接到它,然后有一些动态DNS服务可以为此设置域名到您的动态IP地址,但不建议长期使用。除了可能违反ISP的规则外,它不是一个特别可扩展或强大的解决方案。从长远来看,迁移到托管服务提供商会更有意义。


这是我的困惑 - 我的node.js应用程序是一个WEBSERVER,为什么我需要另外一台服务器(即由heroku,aws等提供的服务器)来托管我的
应用吗?我觉得我错过了什么...


您不需要其他网络服务器。如果您要找到托管服务提供商,您将使用擅长托管node.js服务器的托管服务提供商。对于那些类型的提供者,可能不会有另一个Web服务器 - 您的node.js服务器将是唯一涉及的服务器。他们可能拥有用于使多租户环境工作的代理或负载均衡器,但除了确保遵循正确的安装说明以使您的node.js服务器在其中正常运行之外,您应该在很大程度上不会意识到这些。环境。


So I've got a node app that I can access via localhost:someportnumber. How do I expose this app publicly (i.e. to the rest of the interwebz, not just my local network) using only my machine, and not some sort of hosting service. Machine is a macbook pro, not sure it matters.

Note - this is purely for understanding, I'm not looking to permanently host a toy webapp on my laptop.

Here's my confusion - my node.js application IS A WEBSERVER, why do I need another server (i.e. one provided by heroku, aws, etc) to host my app? I feel like I'm missing something...

解决方案

Assuming this is a home network, then you likely have some sort of router/firewall that connects your home network to the internet. By default that router blocks all incoming connections to the network (for security reasons).

If you want, you can set up what is called a port forwarding rule where you tell the router that you want any incoming connections on port 80 (which is the default http port from a browser) to be routed directly to your macbook pro on your home network. Usually, you would do that by discovering what the IP address is of your macbook pro when it's on your home network and you would set up the port forwarding rule to that IP address. A port forwarding rule would usually be configured through some sort of web-based admin user interface that you can use from a web browser. You'd have to see the manual for your particular router to see how best to connect to it and configure it.

Unless you set your macbook pro to have a static IP address, its IP address will be dynamically assigned by the router. It will likely stay the same for a little while, but can change over time.

Once you've done this, you then need to discover the IP address of your home web connection. This will likely also be dynamically assigned, but also should stay the same for awhile. One you know this IP address, then a browser out on the interwebs can connect to your web server by going the URL http://xxx.yyy.zzzwhere xxx.yyy.zzz is the IP address of your home network as seen from the interwebs.

If you want to be able to connect to it with a normal domain name such as http://mysampledomain.com, then there are some dynamic DNS services that you can pay for that will set up a domain to your dynamic IP address, though this is not recommended for any long term use. Besides probably being against your ISP's rules, it's not a particularly scalable or robust solution. Moving to a hosting provider would make more sense for the long term.

Here's my confusion - my node.js application IS A WEBSERVER, why do I need another server (i.e. one provided by heroku, aws, etc) to host my app? I feel like I'm missing something...

You don't need another web server. If you were to find a hosting provider, you would use a hosting provider that is good at hosting node.js servers. With those type of providers, there would likely not be another web server - your node.js server would be the only one involved. They might have proxies or load balancers that they use to make a multi-tenant environment work, but you should largely be unaware of those other than making sure you follow the proper installation instructions to get your node.js server up and running properly in their environment.

这篇关于在我的机器上托管节点应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆