简体   繁体   English

AWS和Node.js,我需要nginx还是apache?

[英]AWS and Node.js, do I need nginx or apache?

I did post this on serverfault, but not getting any views or responses. 我确实在serverfault上发布了这个,但没有获得任何视图或响应。

I've read a bunch of posts on here about whether or not you need a webserver when using Node.js, and the answer always seems to be yes to serve up static files. 我在这里阅读了一些关于在使用Node.js时是否需要网络服务器的帖子,并且答案似乎总是提供静态文件。

My question is this though. 我的问题是这个。 If the site I'm working on is mostly dynamic, couldn't I just use Node.js as the server and the dynamic parts, and then put all the static files (css, js, images, etc) on CloudFront to serve them up? 如果我正在处理的网站主要是动态的,我不能只使用Node.js作为服务器和动态部分,然后将所有静态文件(css,js,images等)放在CloudFront上为它们服务吗? This way I don't have to worry about caching (through varnish or redis or what have you), or running an http server like nginx and proxying through to get to Node.js (which I've read causes problems with socket.io). 这样我就不用担心缓存(通过清漆或redis或者你有什么),或运行像nginx这样的http服务器并通过代理来访问Node.js(我读过这会导致socket.io出现问题) )。

Along a similar topic, will Amazon's ELB suffice as a load balancer or if the site go big enough to need to be load balanced would I need to do something else? 在类似的话题中,亚马逊的ELB是否足以作为负载均衡器,或者如果站点足够大以需要负载均衡,我还需要做其他事情吗? Thanks in advance! 提前致谢!

I can't speak explicitly to node.js architecture decisions, but I can address your CloudFront and ELB questions. 我不能明确地谈论node.js架构决策,但我可以解决您的CloudFront和ELB问题。

CloudFront is a great CDN for static assets, but there are a few gotchas. CloudFront是静态资产的绝佳CDN,但有一些问题。 As the saying goes, "There are only two hard problems in Computer Science: cache invalidation and naming things." 俗话说“计算机科学只有两个难题:缓存失效和命名事物。” If you want to replace your static assets with identically-named-but-updated assets, you'll have to start mucking with cache-control-headers, which determine how long any given CF node caches an asset. 如果要使用具有相同名称但更新的资产替换静态资产,则必须开始使用cache-control-headers,这将确定任何给定CF节点缓存资产的时间。 There's little advantage to caching in CF if you set it too low. 如果将CF设置得太低,在CF中缓存几乎没有什么优势。 It's such a pain, I strongly recommend versioning your assets and setting up your application in such a way as to deploy assets and updated asset references simultaneously. 这是一种痛苦,我强烈建议您对资产进行版本控制,并以同时部署资产和更新资产引用的方式设置应用程序。 At this time, there is no way to manually expire an object's caching from CF via an API call or some other method. 此时,无法通过API调用或其他方法手动使对象的缓存从CF到期。

As for ELB scaling: Yes. 至于ELB缩放:是的。 Use them. 使用它们。 Netflix does, and if they can you can, too. Netflix确实如此,如果可以,也可以。 The key to ELB use is understanding their role in your application's traffic: You want them to be highly available, which means maintaining a fleet of webservers in multiple availability zones, and making sure the ELB is properly configured to hit them. ELB使用的关键是了解它们在应用程序流量中的作用:您希望它们具有高可用性,这意味着在多个可用区域中维护一组Web服务器,并确保ELB已正确配置以实现它们。 In fact, Netflix recently open-sourced their cloud management application called "Asgard". 事实上,Netflix最近开源了他们的云管理应用程序 “Asgard”。 I suggest checking it out. 我建议检查一下。 The linked blog post has a great explanation of ELB use, and Asgard looks like a decent way to manage cloud deployments with zero downtime. 链接的博客文章对ELB的使用有很好的解释,而Asgard看起来像是一种管理云部署而不需要停机的好方法。

If you're using a framework for Node.js like Express, you can easily specify where your static files are located allowing you to employ a CDN. 如果您使用像Express这样的Node.js框架,则可以轻松指定静态文件所在的位置,从而允许您使用CDN。 You could simply use something like express cdn. 你可以简单地使用像express cdn这样的东西 . If you needed load balancing, there are several ways you could handle it, but EBS would more than likely suffice. 如果您需要负载平衡,有几种方法可以处理它,但EBS很可能就足够了。

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

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