Considering using NGINX to serve magento- I'm not concerned about implementation details, but want to know if anyone has good (or bad) things to say about it. Also of particular interest is using NGINX to load balance magento.

  • we have 2 shops running on a dedicated server with NginX. For high traffic shops there's most certainly a benefit as NginX just handles the requests better and leaves more resources for Magento. For low traffic shops im not sure there is any benefit Commented Jan 26, 2013 at 14:56

2 Answers 2


Nginx is definitely a good choice for hosting Magento, and it comes with a number of nice (but small) benefits that can help improve site performance.

The main difference between Nginx and Apache is that Nginx uses non-blocking Evented IO, and Apache just uses multithreading/processing. What is the difference and why does it matter? Well in the case of Apache, say it has 5 threads, it can handle 5 requests for something at any given time. If one of those threads takes a long time to finish, there are only 4 threads left to handle any further incoming requests. If all 5 threads get locked up, then no incoming requests can be handled until one finishes.

With Evented IO when a thread receives a request for something, it fires off an event and moves straight on to the next request. When the event calls back, it then passes on the response to the relevant client.

This is roughly similar to how asynchronous javascript works. You fire off an AJAX request and continue on until you get a callback.

This modern approach is well suited to serving lots of small static files without the overhead of spawning lots of threads or worker system proceses.

The other benefit of Nginx is its low memory footprint. Apache supports A LOT of stuff, and in doing so has a high memory and computational footprint. You can pare it back but Nginx is architected from scratch to be lean in terms of memory.

The differences are not huge, but as you scale up to many thousands of requests those small differences, in aggregate, make a big difference.

Now it is important to remember that the biggest performance bottleneck in a Magento application is the execution of PHP code. Here there is a basically negligible difference in performance between Apache and Nginx. The important thing is to use PHP-FPM, and the worker MPM with Apache (and definitely avoid prefork/mod-php). The main reason is that you only invoke a PHP interpreter when you need to execute PHP code, and you can use op-code caching software like APC effectively (and this is the single biggest performance boost you will get).

Last point to make: some modules/applications expect Apache to be used and the documentation may be geared on the use of ModRewrite or use of .htaccess files. While there is ModRewrite style support in Nginx, there isn't support for per directory .htaccess style solutions.

Personally, I like Nginx because it serves static content efficiently, it's very easy to setup PHP-FPM and I quite like its configuration syntax. It's not a magic bullet solution to performance problems, but it's robust flexible option to consider.

  • 1
    A great answer which is backed by Magento, Inc. findings: magentocommerce.com/whitepaper
    – benmarks
    Commented Jan 26, 2013 at 15:41
  • Yup agree with Aaron 100%, We too use Nginx for most of our Magento deployments because of its ability to server static content faster and handle a higher number of concurrent requests as compared to Apache. The only downside we've come across with Nginx is on one of our projects, it randomly throwing a 504 gateway timeout error (even when server loads are quite low). We've yet to nail this one yet.. most of the solutions described in various forums haven't helped much. Commented Jan 30, 2013 at 18:57

I would say the performance benefit of Nginx when using Magento is neglectible. The event-based IO advantage as mentioned by Aaron also applies to Apache (when using the event MPM).

Speaking about Magento in general, most processing (99%) takes place in PHP and the database, so optimizing the first 1% will give you relatively little benefit.

However, there are other reasons to chose Nginx for Magento, such as a smaller memory footprint, better rate limit and SPDY support, to name a few.

There is a large disadvantage to Nginx when converting existing Magento sites running on Apache, since many .htaccess statements don't directly map onto Nginx statements. For example, Nginx doesn't support hostnames in ACLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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