Should i use apache or nginx




















Get the latest tutorials on SysAdmin and open source topics. Hollie's Hub for Good Supporting each other to make an impact. Write for DigitalOcean You get paid, we donate to tech non-profits. Apache and Nginx are the two most common open source web servers in the world. Both solutions are capable of handling diverse workloads and working with other software to provide a complete web stack.

While Apache and Nginx share many qualities, they should not be thought of as entirely interchangeable. Each excels in its own way and it is important to understand the situations where you may need to reevaluate your web server of choice.

This article will be devoted to a discussion of how each server stacks up in various areas. The Apache web server has been the most popular server on the internet since Because of this popularity, Apache benefits from great documentation and integrated support from other software projects.

Apache is often chosen by administrators for its flexibility, power, and widespread support. It is extensible through a dynamically loadable module system and can process a large number of interpreted languages without connecting out to separate software. In , Igor Sysoev began work on Nginx as an answer to the C10K problem, which was a challenge for web servers to begin handling ten thousand concurrent connections as a requirement for the modern web.

The initial public release was made in , meeting this goal by relying on an asynchronous, events-driven architecture. Nginx has grown in popularity since its release due to its light-weight resource utilization and its ability to scale easily on minimal hardware. Nginx excels at serving static content quickly and is designed to pass dynamic requests off to other software that is better suited for those purposes. Nginx is often selected by administrators for its resource efficiency and responsiveness under load.

One big difference between Apache and Nginx is the actual way that they handle connections and traffic. This provides perhaps the most significant difference in the way that they respond to different traffic conditions. Apache provides a variety of multi-processing modules Apache calls these MPMs that dictate how client requests are handled.

Basically, this allows administrators to swap out its connection handling architecture easily. These are:. As you can see, Apache provides a flexible architecture for choosing different connection and request handling algorithms. Nginx came onto the scene after Apache, with more awareness of the concurrency problems that would face sites at scale.

Leveraging this knowledge, Nginx was designed from the ground up to use an asynchronous, non-blocking, event-driven connection handling algorithm. Nginx spawns worker processes, each of which can handle thousands of connections. The worker processes accomplish this by implementing a fast looping mechanism that continuously checks for and processes events. Decoupling actual work from connections allows each worker to concern itself with a connection only when a new event has been triggered.

Each of the connections handled by the worker are placed within the event loop where they exist with other connections. Within the loop, events are processed asynchronously, allowing work to be handled in a non-blocking manner.

When the connection closes, it is removed from the loop. This style of connection processing allows Nginx to scale incredibly far with limited resources. Since the server is single-threaded and processes are not spawned to handle each new connection, the memory and CPU usage tends to stay relatively consistent, even at times of heavy load.

In terms of real world use-cases, one of the most common comparisons between Apache and Nginx is the way in which each server handles requests for static and dynamic content. Apache servers can handle static content using its conventional file-based methods. The performance of these operations is mainly a function of the MPM methods described above. Apache can also process dynamic content by embedding a processor of the language in question into each of its worker instances. This allows it to execute dynamic content within the web server itself without having to rely on external components.

These dynamic processors can be enabled through the use of dynamically loadable modules. Communication does not need to be coordinated with an additional piece of software and modules can easily be swapped out if the content requirements change.

Nginx does not have any ability to process dynamic content natively. To handle PHP and other requests for dynamic content, Nginx must pass to an external processor for execution and wait for the rendered content to be sent back. The results can then be relayed to the client.

This can complicate things slightly, especially when trying to anticipate the number of connections to allow, as an additional connection will be used for each call to the processor. However, this method has some advantages as well. Since the dynamic interpreter is not embedded in the worker process, its overhead will only be present for dynamic content. Static content can be served in a straight-forward manner and the interpreter will only be contacted when needed.

Apache can also function in this manner, but doing so removes the benefits in the previous section. For administrators, one of the most readily apparent differences between these two pieces of software is whether directory-level configuration is permitted within the content directories. Apache includes an option to allow additional configuration on a per-directory basis by inspecting and interpreting directives in hidden files within the content directories themselves.

These files are known as. Since these files reside within the content directories themselves, when handling a request, Apache checks each component of the path to the requested file for an.

This effectively allows decentralized configuration of the web server, which is often used for implementing URL rewrites, access restrictions, authorization and authentication, even caching policies. While the above examples can all be configured in the main Apache configuration file,.

First, since these are interpreted each time they are found along a request path, they are implemented immediately without reloading the server. Second, it makes it possible to allow non-privileged users to control certain aspects of their own web content without giving them control over the entire configuration file. This provides an easy way for certain web software, like content management systems, to configure their environment without providing access to the central configuration file.

This is also used by shared hosting providers to retain control of the main configuration while giving clients control over their specific directories. Nginx does not interpret. Remember, Apache has been around for a very long time so there are a lot of resources and third-party add-ons available. And if you're looking to serve up dynamic content, Apache's built-in ability to parse and execute numerous types of scripting languages, makes it really flexible.

If you want flexibility, go with Apache. You don't want to miss our tips, tutorials, and commentary on the Linux OS and open source applications. Delivered Tuesdays. He's covered a variety of topics for over twenty years and is an avid promoter of open source. For more news about Jack Wallen, visit his website jackwallen Watch Now. Delivered Tuesdays Sign up today. Editor's Picks. It's time to dump Chrome as your default browser on Android. Translating to the system when necessary. For file system directory, instead passes their URI itself.

Passing requests as URI instead of file system locations allow Nginx to function easily in both web and proxy server. It configures simple by laying out how to respond to diff requests patterns.

This very design of interpreting requests as URI locations allows Nginx to easily function as not only a web server but also as a proxy server, load balancer, and HTTP cache. Also, in the Apache vs Nginx contest, NGINX again wins when it comes to the transfer rate the speed at which data was sent from the server to the client.

Both are extensible through module systems. But the way they work is different. Apache server has a rich set of features that can be enabled by installing one of the 60 official modules. There are also many other unofficial modules that can be easily found on the internet. Its module system allows you to dynamically load or unload modules to satisfy your needs. Its modules can be turned ON or Off to add or remove functionality and to hook into the main server.

In short, Apache has several feature modules to meet your need but many of them are not used often. Nginx, on the other hand, is selected and compiled into the course of the 3rd party plugins.

Not dynamically loadable. The modules are useful though, they allow you to dictate what you want from your server by only including the functionality you intend to use. It is considered much more secure than Apache server as arbitrary components can be hooked in the server.

Note: Apache is like Microsoft Word and Nginx is like notepad. Apache has a million options but you only need a few. Flexibility is one of the most important concerns when it comes to a web server. Apache vs Nginx flexibility has some interesting differences.

Customizations to the web server can be done through riding modules. Apache has had dynamic module loading for the longest time, so all Apache modules support this. Apache vs Nginx security is again a debated topic. Well, both of these web servers offer great extended security for its C-based code base.

Apache makes sure that all the website that runs on its server are safe from any harm and hackers. Talking about security and Apache, you must read our detailed post on cPanel security. A secured cPanel means a secured website. The NGINX code base, however, is significantly smaller by several orders of magnitude, so that is definitely a big plus from a forward-thinking security perspective. NGINX also has a list of recent security advisories. Support is something that every customer looks keenly for.

It can make or break your user experience. While comparing Apache vs Nginx support, there seems to be no big difference. Commercial Apache support is available from a number of third-party companies, such as OpenLogic, but no official list is maintained by the Apache Foundation.

Apache server is meant to offer great support to all of its users. The support is almost same in both. Both web servers are great. And after going over the benefits, limitations, and differences, you may already have an idea of the best web server for you.

Still confused about which server is the better solution for you? However, with Apache, you get an advantage to give the non-privileged users control over some important aspects of their website.

Nginx has some core modules that are very important. Howbeit, there are some functionality limitations with Nginx. In case of some limitations or needing to use extra modules that are not supported by Nginx, you might want to choose Apache instead.

This significantly improves the overall performance of backend servers. Nginx is incessantly trying to serve its users a better experience. It has shown some remarkable growth in the year Take a glance at the key takeaways from on the Nginx blog.

If we talk about the speed and how many clients can be served on a high load, Nginx will always shine as a winner over Apache.

This makes Nginx significantly lightweight and great for server resources. This is why most of the web developers prefer Nginx over Apache. Especially, the e-stores today hire a Magento developer that knows how to work on a high-traffic website, and adept in working on Nginx. In a nutshell, when it comes to serving a website with a large volume of traffic, there is no beating Nginx.



0コメント

  • 1000 / 1000