Nginx 作为 Apache 的反向代理是否仅对动态内容提供帮助
我计划将所有静态内容移至 CDN,以便在我的服务器上只剩下动态内容。我现在将 Nginx 设置为 Apache 的反向代理。传入的静态请求由 Nginx 直接传递,无需转到 Apache。
在这种情况下,Nginx 处理了很大一部分请求,我可以清楚地看到 Nginx 的必要性。
既然我把所有静态内容都移到了另一个域,那么Apache前面还需要有nginx吗?因为现在所有的请求默认都是动态请求并且全部转到Apache。
仅针对动态内容运行 Nginx 和 Apache 是否还有其他好处?
我的动态内容是 PHP/MySQL
编辑:
需要明确的是:我现在将 Nginx 作为反向代理。它提供静态和动态内容。但我正在将静态文件移动到 CDN。那么我的域名上还需要 Nginx 吗?
I am planning to move all my static content to a CDN so on my server I only have dynamic content left. I now have Nginx set up as reverse proxy to Apache. The static request that came in where directly delivered by Nginx without having to go to Apache.
In this case Nginx handled a large portion of the request and I can clearly see the necessity of Nginx.
Now that I moved all the static content to another domain, is there still a need to have nginx in front of Apache. Because now all the request are by default dynamic requests and all go to Apache.
Are there any other benefits of having Nginx and Apache running for only dynamic content.
My dynamic content is PHP/MySQL
Edit:
To be clear: I now have Nginx as a reverse proxy. It delivers static and dynamic content. But I am moving my static files to a CDN. Do I then still need Nginx on my domain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,你绝对需要在 Apache 之前使用 nginx。 Apache 每个连接使用 1 个线程或进程。这些线程中的每一个都占用内存。如果有几百人访问您的网站并且启用了 keepalive,则每个浏览器都会让 apache 进程或线程忙于占用服务器上的内存。
您可以通过在 apache 服务器上禁用 keepalive 来解决此问题,但这会降低网站的性能,因为浏览器无法重用连接。
因此,您可以使用 nginx 作为启用 keepalive 的反向代理。它可以用很小的内存占用(大约 8 兆)维持数千个连接。因为 nginx 位于 apache 服务器本地,所以每个请求仅占用 apache 子进程或线程几微秒。这意味着您只需很少的 apache 进程就可以为数千人提供服务。
此外,nginx 的配置比 apache 更加灵活,并且通过将其放在前端,它为您提供了很大的灵活性。
Yes you absolutely do need nginx in front of Apache. Apache uses 1 thread or process per connection. Each of these threads occupy memory. If you have a few hundred people visiting your website and you have keepalive enabled, each of these browsers will keep an apache process or thread busy occupying memory on your server.
You can work around this by disabling keepalive on your apache server but this slows down the performance of your website because browsers can't reuse connections.
So instead you use nginx as a reverse proxy with keepalive enabled. It can maintain thousands of connections with a tiny memory footprint (about 8 megs). Because nginx is local to your apache server each request only occupies an apache child or thread for a few microseconds. That means you can serve thousands of people with only a tiny handful of apache processes.
Also nginx's configuration is much more flexible than apache and by having it on the front end it gives you a lot of flexibility.
我为一个网站所做的事情是:
这无需设置两个域:全部都在同一个域上。
基本上,我所做的是:
我的 nginx 配置文件如下所示:
现在,为什么要做这样的事情呢?
好吧,nginx 应该:
因此,我认为它可以帮助网站有一点流量,以降低 Apache 的负载。
What I've done for one website is :
This without having to set up two domains : all is on the same domain.
Basically, what I've done is :
Here's how my nginx's configuration file looks like :
Now, why do such a thing ?
Well, nginx is supposed to :
So, I suppose it could help on a website with a bit of traffic, to lower the load that's put on Apache.
不,你不再需要 nginx 了。
No, you don't need nginx anymore.
您还可以使用 nginx 从 apache 实例卸载 SSL 处理。
例如,我们有一个堆栈配置有 nginx->haproxy->apache 服务器池。 nginx 和 haproxy 共同生活在一个 heartbeat 集群上,并将请求发送到后端的 apache 盒子池中。我们在 nginx 前端安装所有 SSL 证书。
You can also use nginx to offload SSL processing from the apache instances.
For example, we have one stack configured with nginx->haproxy->pool of apache servers. nginx and haproxy live together on a heartbeat cluster and feed requests into a pool of apache boxes on the backend. We install all the SSL certs on the nginx frontend.
如果您使用 Apache 1.3,前面的 nginx 是最好的解决方案:
nginx 可以轻松地为数千个连接提供服务,但 Apache 不能
nginx in front is the best solution in case you use Apache 1.3:
nginx can easily serve thousands of conections, but Apache can't