Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will an Nginx as reverse proxy for Apache help on dynamic content only

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.

like image 550
Saif Bechan Avatar asked Apr 16 '10 17:04

Saif Bechan


People also ask

Can Nginx be used for dynamic content?

NGINX can deliver static content locally, but for dynamic content it acts as proxy in front of other servers that deliver the dynamic application content, thus keeping NGINX lean and leaving the generation of dynamic content to servers that specialize in it, such as FastCGI‑ or uwsgi‑based servers, application servers ...

Why use nginx reverse proxy for Apache?

Using Nginx as a reverse proxy for Apache will allow both servers to work together and allow you to take advantage of the benefits of both servers. You can easily monitor what traffic goes in and out through the reverse proxy.

Can Nginx be used as reverse proxy?

Nginx is an open source web server that can also serve as a reverse proxy. Apart from being used to host websites, it's also one of the most widely used reverse proxy and load balancing solutions.

When you configure Nginx as a reverse proxy for Apache both may listen to the same port?

You do that by configuring NGINX as a reverse proxy for Apache. With this setup, NGINX will listen for all incoming requests to port 80 and pass them on to Apache, which is listening in on port 8080.


1 Answers

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.

like image 158
Mark Maunder Avatar answered Oct 20 '22 17:10

Mark Maunder