为什么 node.js 不能在共享主机上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17529613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why node.js can't run on shared hosting?
提问by Yousuf Memon
First thing:I searched all of the known web hosting companies for shared hosting of nodejs but I didn't find anyone. Then I came to know that nodejs cannot run on a shared host system. I want to know why?
第一件事:我搜索了所有已知的网络托管公司以获取 nodejs 的共享托管,但没有找到任何人。然后我才知道 nodejs 不能在共享主机系统上运行。我想知道为什么?
Second thing:I am a normal guy with a normal budget. Choosing a vps or deicated server or cloud hosting makes the node run, but its out of my pocket money range as compared to the PHP shared hosting services, so should I learn node.js?
第二件事:我是一个预算正常的普通人。选择 vps 或专用服务器或云托管使节点运行,但与 PHP 共享托管服务相比,它超出了我的零花钱范围,所以我应该学习 node.js 吗?
回答by moka
Theoretically it can, but practically it depends on hosting provider to have such infrastructure in place.
理论上可以,但实际上取决于托管服务提供商是否拥有此类基础设施。
Node comparing to classic web platforms is self-sustainable platform. In case with PHP (for example), it runs on with of apache or nginx (or any other), and PHP it self is just script language with some libraries that does not do much apart of logic implementation, and requires web server solution. Web server creates socket to listen specific ports for traffic, will do its own magic and will execute PHP to process requests.
与经典 Web 平台相比,Node 是可自我维持的平台。如果使用 PHP(例如),它可以与 apache 或 nginx(或任何其他)一起运行,而 PHP 本身只是脚本语言,带有一些库,除了逻辑实现之外,它并没有做太多的逻辑实现,并且需要 Web 服务器解决方案。Web 服务器创建套接字来侦听特定端口的流量,将发挥自己的作用并执行 PHP 来处理请求。
In meantime node.js creates own socket, and binds it to own port. That gives it much more low-level access, so it is web server it self. You can't bind to one port two applications, so it already unsharable.
There are services (web servers) that allow you to create proxy to route traffic to your node.js process but that is not as efficient in some cases, and shared hosting does not provide such functionality.
同时 node.js 创建自己的套接字,并将其绑定到自己的端口。这为其提供了更多的低级访问权限,因此它本身就是 Web 服务器。您无法将两个应用程序绑定到一个端口,因此它已经不可共享。
有些服务(Web 服务器)允许您创建代理以将流量路由到您的 node.js 进程,但在某些情况下效率不高,并且共享主机不提供此类功能。
As node.js is still fairly young as well as is well, different, it still did not hit majority of shared hosting services. There are some available services online to host your node.js applications in a 'shared' manner.
由于 node.js 还很年轻,而且还很不同,它仍然没有影响大多数共享托管服务。有一些可用的在线服务以“共享”方式托管您的 node.js 应用程序。
Additionally you can rent EC2 Micro instance on AWS for free (Free Tier) for one year, which gives you plenty possibilities and time to try and test different stuff. You'll get semi-dedicated system, where you can do pretty much anything (install software, modify OS configurations, and much more), where shared hosting would not allow you to do so.
此外,您可以在 AWS 上免费租用 EC2 Micro 实例一年(免费套餐),这为您提供了大量的机会和时间来尝试和测试不同的东西。您将获得半专用系统,您几乎可以在其中执行任何操作(安装软件、修改操作系统配置等等),而共享主机则不允许您这样做。
回答by Ed.
Look into Heroku. For simple low traffic apps, they are free and can easily be scaled for more traffic (for an added cost). Additionally, you use Git to deploy, so is really simple to get stuff updated...
看看 Heroku。对于简单的低流量应用程序,它们是免费的,并且可以轻松扩展以获得更多流量(增加成本)。此外,您使用 Git 进行部署,因此更新内容非常简单......
回答by jh314
回答by Thinking Sites
Node doesn't work like most servers. With IIS and Apache, there is one server running multiple sites, which lends itself to shared environments. With Node, you're running your own server so instead you tend to share resources on a machine.
Node 不像大多数服务器那样工作。使用 IIS 和 Apache,一台服务器运行多个站点,这适用于共享环境。使用 Node,您可以运行自己的服务器,因此您倾向于在机器上共享资源。
I can't tell you whether it's worth learning node because I don't know your motivation, but it can expand your career opportunities if you choose to go there, and to expand your skillset.
我不能告诉你是否值得学习 node,因为我不知道你的动机,但如果你选择去那里,它可以扩展你的职业机会,并扩展你的技能。
Here are a couple of hosting options in the low price range.
这里有几个低价范围的托管选项。
回答by Svbaker
Other great node app hosting options include Joyent's SmartOS and Microsoft Azure. Both have a free trial period.
其他出色的节点应用托管选项包括 Joyent 的 SmartOS 和 Microsoft Azure。两者都有免费试用期。
Azure can be a great learning platform for node.js as you can host your node app in Windows Server, Ubuntu Linux, or Azure's special "web site" shared deployment scheme.
Azure 可以成为 node.js 的绝佳学习平台,因为您可以在 Windows Server、Ubuntu Linux 或 Azure 的特殊“网站”共享部署方案中托管您的节点应用程序。
http://www.windowsazure.com/en-us/develop/nodejs/tutorials/create-a-website-(mac)/
http://www.windowsazure.com/en-us/develop/nodejs/tutorials/create-a-website-(mac)/
Another cost efective solution for node app hosting is Azure's "Web Site" approach - about $10 per month. The down side is that you have to use their shared environment that hosts your node app via IIS. In practice, this worked for well for me, but you are limited in that you can't use certain Linux functions from Node when it's running on Windows, and you won't learn how to configure the node service yourself, which may or may not be important to you. (Note: Azure's GIT deployment process works great if you want to deploy your app from a local GIT repository. Also note that NodeIIS will stop your node app when it's not in use for a certain period of time - and it auto-starts again when a request for your app comes in.)
另一个用于节点应用托管的经济高效的解决方案是 Azure 的“网站”方法——每月约 10 美元。不利的一面是您必须使用他们通过 IIS 托管您的节点应用程序的共享环境。在实践中,这对我来说效果很好,但是您的局限性在于,当 Node 在 Windows 上运行时,您无法使用 Node 的某些 Linux 功能,并且您不会学习如何自己配置节点服务,这可能或可能对你不重要。(注意:如果您想从本地 GIT 存储库部署您的应用程序,Azure 的 GIT 部署过程非常有效。另请注意,NodeIIS 会在您的节点应用程序在一段时间内不使用时停止它 - 并且它会在对您的应用程序的请求进来了。)
Joyent's SmartOS platform is a Linux OS optimized for hosting your node.js app. They have impressive reliability and performance as well as great diagnostic tools.
Joyent 的 SmartOS 平台是一个 Linux 操作系统,针对托管您的 node.js 应用程序进行了优化。它们具有令人印象深刻的可靠性和性能以及出色的诊断工具。
http://wiki.joyent.com/wiki/display/jpc2/Developing+a+Node.js+Application
http://wiki.joyent.com/wiki/display/jpc2/Developing+a+Node.js+Application
The most cost effective solution I have found so far is DigitalOcean, a great new hosting solution where you can host a full Linux VM for only $5/month! I have had great luck hosting Node apps there so far: https://www.digitalocean.com/pricing
到目前为止,我发现的最具成本效益的解决方案是 DigitalOcean,这是一个很棒的新托管解决方案,您只需每月 5 美元即可托管完整的 Linux VM!到目前为止,我很幸运在那里托管 Node 应用程序:https: //www.digitalocean.com/pricing
回答by user2473015
a2hosting allows Node.js in shared hosting.But don't have experience there.Found from a web search
a2hosting 允许共享主机中的 Node.js。但没有那里的经验。从网络搜索中找到
Update : Use DigitalOcean. Private VPS
更新:使用 DigitalOcean。私人 VPS

