Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone enlighten me whats the advantage of having NginX as a reverse proxy to Apache. People suggest it so that static content is handled by nginx and dynamic content (php files) are handed over to Apache.

  1. Wouldn't directly letting php-fcgi/php-fpm handle those PHP files a lot more reasonable than letting Apache's mod_php handle it?

  2. What are the advantages (performance wise)

  3. If I choose to reverse proxy, would I need to do a nginx rewrite or would the .htaccess from apache work as it is? (because its reverse proxied, so the calls are directed to apache right?)

TY in advance

share|improve this question
up vote 4 down vote accepted

Reverse proxying is slower and generally worse, however, some reasons to use it is to maintain (some) compatibility with .htaccess files (which you would have to write (and that isn't always practical) is you use a pure nginx setup) or if you require specific apache modules. (Some may argue that is you have these requirements, it is easier to just use apache.)

  1. PHP-FPM with nginx would be the preferred solution - you get the fast static file serving of nginx and good PHP performance without adding additional overhead, proxying, or the (typically) significant memory usage of apache.
  2. nginx+PHP-FPM is (typically) faster and uses less memory. Nginx + Apache + FastCGI/FPM will still serve static files fast, but will have additional overhead on the dynamic files (not as bad as mod_php, but worse than if you eliminate apache).
  3. You will need a bit of both - nginx would need to know how to deal with the paths (e.g. for serving static files, denying access to .htaccess, etc) and apache will need to know how to handle the files. In some cases, if your .htaccess file doesn't pertain to static files (so every request that needs rewriting is going to go to apache), then it may be acceptable to simply deny access to certain locations, and have apache do the rest via .htaccess - it doesn't seem ideal, will cost a bit in performance, and its reliability is questionable - but it could work on a simple setup).

If you can, go with the straight nginx+PHP-FPM setup. If you can't, while there may be some merits to reverse-proxying, think through the repercussions, especially if you are dependent on .htaccess files.

share|improve this answer
Thanks for the clear answer. I actually went with nginx+php-fpm+mysql way. I was just wondering about the advatages of reverse proxy, as I've heard it does some 'caching' too. (well if I would want caching, i'd go with varnish). A competitor of mine have setup a nginx server to serve static video files. The actual setup was nginx reverse proxy -> nginx server. I just don't get it why he even setup a nginx installation to proxy a nginx installation. – Ansell Aug 5 '11 at 20:05
Nginx is a very versatile server - it certainly can do caching (and SSL termination, and even some rudimentary load balancing) however the limitation of caching is telling nginx when to expire the cache (typically adding versions to your files) - it doesn't have the same caching capabilities as varnish which can be triggered to clear the cache on application specific events. – cyberx86 Aug 5 '11 at 20:10

I would say that it's the other way around: cutting Apache out of the mix will increase performance. You'd keep Apache around if you like some of the other modules Apache provides, or if you have some external reason to keep using Apache for your dynamic content.

It should be fine to let Apache handle the rewrites, so long as you don't do anything to accesses of your static content. But make sure to have an exclude for .ht* in your nginx conf: don't want to accidentally serve those particular static files out to the general public.

share|improve this answer
Hi, Yes thats what I was thinking. Leaving out apache out of the system is more reasonable than reverse proxying. I was just wondering about the advantages of reverse proxying to letting nginx handle it all. Or does it even have any advatanges? (other than apache modules that I would need) – Ansell Aug 5 '11 at 20:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.