5 ms·
I am a person that doesn't really understands webserver software. What is approximately the difference between Apache and Nginx? Also, should I stop using LAMP
by runn1ng 13y ago
I am a person that doesn't really understands webserver software. What is approximately the difference between Apache and Nginx?
Also, should I stop using LAMP stack for my small and experimental PHP websites that very few people visit, or is it good enough?
- metachris 13y agoFor me the main reasons to switch from Apache to Nginx were that it's smaller, faster, very flexible and easier to configure. Plus the additional features (eg. reverse proxy, ...).
- sciurus 13y agoHuh? Apache has been able to act as a reverse proxy since the 1990s. See https://httpd.apache.org/docs/current/mod/mod_proxy.html https://httpd.apache.org/docs/current/mod/mod_proxy.html There's a list of all the official Apache modules at https://httpd.apache.org/docs/current/mod/ https://httpd.apache.org/docs/current/mod/. Also, there are many third party modules.
- stephenr 13y ago"Reverse proxy" is not an "additional feature" of nginx. Apache can serve as a reverse proxy to a web server, or even a fully functional forward proxy for lan users to the internet. Nginx was never meant to have more features than Apache, it's intended to be lightweight and fast. If you can imagine it, Apache is likely to have a module for it. With nginx, not so much.
- ameswarb 13y agoApache is a process- and thread-driven application, but Nginx is event-driven. The practical effect of this design difference is that a small number of Nginx "worker" processes can plow through enormous stacks of requests without waiting on each other and without synchronizing; they just "close their eyes" and eat the proverbial elephant as fast as they can, one bite at a time. Apache, by contrast, approaches large numbers of requests by spinning off more processes to handle them, typically consuming a lot of RAM as it does so. Apache looks at the elephant and thinks about how big it is as it tucks into its meal, and sometimes Apache gets a little anxious about the size of its repast. Nginx, on the other hand, just starts chomping. The difference is summed up succinctly in a quote by Chris Lea on the Why Use Nginx? page: "Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache." Source: http://arstechnica.com/business/2011/11/a-faster-web-server-ripping-out-apache-for-nginx/ http://arstechnica.com/business/2011/11/a-faster-web-server-...
- antihero 13y agoIsn't Apache's default MPM event driven since 2.4 anyway?
- FooBarWidget 13y agoevent_mpm is only partially evented. Thanks to the Apache module API, which assumes blocking I/O, it's impossible for Apache to be fully evented. That said, event_mpm handles a lot of the important cases where evented I/O is desired.
- yuvadam 13y agoFor small scale stuff, there's practically no difference between apache and nginx. For larger scale deployments, nginx is generally considered to perform better than apache.
- threeseed 13y agoEven for small scale stuff there are some benefits to using Nginx. There is the ability to use Lua with MySQL, PostgreSQL, MemCache, Redis, Upstream etc to perform functions of an app server e.g. authenticate users, serve JSON from a database. It's fast and keeps your app layer focused on real business logic.
- bradleyland 13y agoThe grandparent poster mentions they're using a LAMP stack, so the ability to use Lua for a service tier seems like a pretty obscure tangent.
- sciurus 13y agoNot that nginx isn't great technology, but Apache has mod_lua too. Also, mod_perl used to be very popular for embedding the kind of functionality you talk about in the web server. https://httpd.apache.org/docs/current/mod/mod_lua.html https://httpd.apache.org/docs/current/mod/mod_lua.html http://modperlbook.org/ http://modperlbook.org/
- njharman 13y agoFor small sites, I would word that as: If you already have Apache, don't bother switching. If you're starting new, use Nginx.
- singlow 13y agoEven for small scale stuff, the "default" nginx way of using PHP is much better - with php running in its own process via php-fpm or fastcgi. If you are running Apache with PHP-FPM you can get similar performance, but you find fewer how-tos and documentation on that since most Apache users leave modphp in place. With modphp in limited memory environments you run into memory swap issues super fast unless you are careful about your Apache configs, since it will, in most default environments, spawn many more Apache processes than you have memory for. PHP makes the Apache process use 20-200M of memory for many standard apps like drupal or wordpress. Put it on a 1Gig linode without turning down the MaxClients and add 10 concurrent users and you will see the site grind to a halt. Now install nginx and php-fpm and follow anyone's basic how-to, it will only spawn as many php processes as your memory and cpu cores can handle, and nginx will keep spinning out the static files while php is churning in the background, living within reasonable memory bounds. You can achieve the same thing in Apache, but I never really knew how to do that until Nginx taught me. I have never seen Apache set up right for this in any of my clients' existing servers and they can never scale at all. Modphp is a bit faster if you have enough memory for your PHP application * the number of simultaneous connections, but that is hardly ever the case, since Apache will be reusing the same high memory processes for every jpg and css file that it does for all of the php requests and 2-3 simultaneous users can make 20-30 concurrent requests. You better make sure that your maxclients is set to your physical memory divided by your php app's memory use. In a 1G VPS this might be 1024M/64M = 16. Save some memory for MySQL if it is on the same server and you probably shouldn't have MaxClients over 10. Now all of the css, jpg and png files are waiting in-line for the 500ms php scripts to finish and the site loads slow. Many PHP apps eat up over 128M per process, even though a typical request is smaller, that one crazy request eventually bloats all of the processes and you are swapping. If PHP starts hitting swap, your request times are rising up to 3-5 seconds real quick.
- pavs 13y ago"Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache." Chris Lea
- TylerE 13y agoI'm not so sure I agree with that. Nginx is actually pretty featureful these days.
- FooBarWidget 13y agoBut all those features can be implemented efficiently. There are a lot of things that Nginx does not support, that would make Nginx slower if it did support that. .htaccess support for example.
- TylerE 13y agoThis may be arguing semantics, but I don't consider that a feature, as anything doable via .htaccess is doable via the main config. (not to mention that nginx supports graceful hot reloads so it's not a problem to manually force it to rescan the main config.
- FooBarWidget 13y agoThe WordPress Supercache plugin automatically sets up a .htaccess with mod_rewrite rules to enable caching. On Apache, it just works. On Nginx without .htaccess support it would have to tell the user to copy-paste a snippet. Ouch, not so friendly. And this is even assuming the user has access to the web server config file.
- TylerE 13y agoCould just as easily drop a file in conf.d in a typical distro nginx install too.
- 13y ago
- xionon 13y agonginx is a good tool, and you should probably twiddle with it sometime so you know what it's about. As far as I know, nginx can do anything Apache can do. nginx is generally faster than Apache. Apache can include modules without a recompile, nginx often requires you recompile to add features. nginx can be used as a reverse-proxy, a load balancer, or a thin SSL / SPDY layer, and succeed; Apache isn't as well suited to non-traditional web serving. Personally, I find nginx's configuration syntax nicer to read and write than Apache's. LAMP is fine for small experimental websites. Do what you're comfortable with! The scale at which the differences between nginx and Apache actually matters is pretty large.
- stephenr 13y agothere is plenty apache does that nginx doesn't do. Also, as stated in another comment, apache can do reverse or forward proxying. Anyone trying to argue for nginx on the basis of better feature support (over apache) is blind to the reality of things.
- tracker1 13y agoNginX can act as a caching proxy with less overhead and faster response times than Apache does, and even more so under heavy load.
- deleted 13y ago[deleted]
- chrismealy 13y agoFifteen years of apache configs was enough for me. I'd use nginx if it was half as fast.
- DirtyMonkey 13y agoCompletely agree with this. After a lot of tweaking I could get Apache (w/ the worker MPM) pretty close to the speed of NGINX, but the difference in configuration files was enough to convert me. And with NGINX I understand _every_ line in the configuration files, with Apache it was almost like configuring by coincidence.
- lmm 13y ago>Also, should I stop using LAMP stack for my small and experimental PHP websites that very few people visit, or is it good enough? It's plenty good enough; it's worked for decades already. If it ain't broke don't fix it. If traffic on a site is ramping up to the point where you're thinking "I might need to get new hardware for this soon", that's the time to start looking at a higher-performance webserver. And honestly I'd look at moving away from PHP more urgently than moving away from Apache, if only because of their respective security records.
- Osiris 13y agoReally? It's a heck of a lot easier to migrate your web server than to re-write your entire codebase in another language.
- mortehu 13y ago> I'd look at moving away from PHP more urgently than moving away from Apache, if only because of their respective security records. In my opinion, this is like moving away from C due to its security record.
- lmm 13y agoWhat, a good idea?
- mortehu 13y agoWell, you did also say "If it ain't broke don't fix it", so we might be agreeing. You wouldn't want any new programming language to roll its own SSL library rather than using OpenSSL or GnuTLS, would you?
- lmm 13y agoI wouldn't want a project to write its own SSL library no, but I would not start a new project in C, and if I had an existing C codebase I would seriously think about migrating it to a safer language (unless it needed particular C features. Crypto code does, because it needs to resist timing attacks, but that's a very rare case).
- nathan_long 13y agoApache executes dynamic code using modules that it loads at boot time. Nginx makes you compile in the ones you want to use. That helps make it faster.
- sciurus 13y agoCheck out the C10K problem. http://www.kegel.com/c10k.html http://www.kegel.com/c10k.html
- cenhyperion 13y agoYou shouldn't stop using your LAMP stack. The differences between how the two behave really only come into play when you're talking about thousands upon thousands of concurrent users.
- tracker1 13y agoUnless you are doing it all on the same server... having less load from one part of the server means more available for other parts, which can lead to a better overall user experience. It's not quite a drop in replacement, but could be well worth considering... trying to get under 300ms page loads shouldn't be just for the big boys.
- jayflux 13y agoIt seems to me like Apache was designed more for hosting multiple websites for different users (the .htacces for example) With Nginx It's not so easy for a jailed user to change his settings unless he's given access to the config. Just my opinion.