Continue with NGINX or switch to Apache ?

June 4, 2016 551 views
Apache Nginx PHP

Hi everyone,

I've read many opinions about NGINX with dynamic content versus Apache with dynamic content. I must say that most people feel Apache is a little bit faster than NGINX.

On the other hand NGINX is very often used in the context of static content delivery ...

I have both a LAMP as well as a LEMP stack ready and all I have to do is choose between one of them in order deploy my sites.

I will be hosting :

  • a pretty simple Wordpress blog,
  • a few hundred static pages, which will be updated maybe daily as well (not through WP, but for instance through dreamweaver).
  • I will will also be installing a PHP script application which uses MySQL heaily on the same server (or maybe a different one if necessary).
  • This is supposed to happen on a 4G server, which I might upgrade later on.

I have dabbled in both Apache and NGINX and I must say that I found NGINX to be easier to configure. It just made more sense to me. However that is secondary. On the other hand, Apache is ... well Apache. Using NGINX as a proxy for Apache seems like a 'complicated' solution and adds another layer to the setup. Again, some people say it works, some say it doesn't do much. I guess it all depends.

Now for my question ... I would like to get some opinions on what would be a good choice to use. NGINX or Apache ? I can imagine that NGINX with php-fpm is a little slower than apache on the dynamic things, but if there is a traffic spike, maybe NGINX will handle better ? If so, this might be an important thing to consider for me (loosing visitors to time-outs or long request times will cost me). Also ... would NGINX be so much slower with dynamic content / php , that it would be noticeable ?

I know that it's a difficult question to answer, however I would really like to heart, at least some opinions ... they might help me with making my choice.


2 Answers

the same question came into my mind few days earlier, and what i found after searching so many articles and feedback, it's a very little improvement on Apache+Nginx over Nginx alone. so my opinion its not worth the hard work.

Nginx as default works good, but you should search for optimization to make your server fly.

  • Yes .. I came to the same conclusion. I've lookedinto FastCGI (caching with NGINX directly) as well as caching plugins. The advantage of those plugins is that they will purge the cache automatically after a content update.

    As far as FastCGI goes ... I didn't find that ability (I might be wrong, if so then please correct me). This leads to the following problem : if you would like to add static pages which are non-worpdress (for instance dreamweaver designed pages) then the cache update is dependend on expiry directives etc.

    Lets say, that I want to do some A/B testing of pages. That means I have to update those pages with different elements and then test them against each other. After uploading a new page, I'd have to probably purge the cache which is through FastCGI through the command line. Or at least, so it seems ....

    Any ideas / thoughts about this ... anyone ?

To get an Nginx+Apache stack without needing to do the configuration yourself, you might want to take a look at ServerPilot. Here's how ServerPilot configures things:

Using this approach gives you the scalability and HTTP/2 benefits of Nginx with the .htaccess and mod_rewrite flexibility of Apache.

  • Thanks for your reply jasamual ... but does serverpilot also offer pure LEMP stacks without Apache ?

    • You can customize your server for a pure LEMP stack (see here), but it's not a good idea. The idea that cutting Apache out of the stack will speed things up comes from misunderstandings people have about where time is spent. If the goal is to play around and learn about server configuration, that's great. But if the goal is to run a business and make money, you shouldn't waste your time on that.

      • With all due respect, I have asked multiple insiders for advice (professionals) and they all say that having NGINX as a proxy is actually done because so many people don't want switch over completely to another server and still want to get the benefit of being able to serve static pages quicker than Apache can. At the same time NGINX will handle more requests at the same time (for the serving of static pages).

        For dynamic pages (wordpress etc.) NGINX uses php-fpm, which will process PHP efficiently, while NGINX itse;f will use less memory than Apache.

        As far as I learned adding NGINX together with Apache would make sense only if you want to have better performance for static pages (as those are served by NGINX) while you want to keep all the functionality (a plethora of modules) which Apache can offer. This is (according to some real knowledgeable people on the matter) on of the main reasons why Nginx is merely added, instead of completely replacing it ...

        If there is something I am missing in this breakdown, then please let me know.

Have another answer? Share your knowledge.