What is the difference between nginx and apache
One example of the important role of Apache within the Linux world is that its server process name is HTTPd, making Apache a synonym with web server software. Apache uses. There are plenty of tutorials about how to configure, edit, and work with this file as it provides a lot of flexibility in configuring how Apache handles incoming requests.
Some examples are: different redirection rules , maximum upload file sizes , URL rewrites, memory limits , directory protection htpasswd , expires headers , cache-control headers , encoding headers , cookies, query string manipulations.
However, settings and rules from your. For shared hosting providers , this is a dream because they can provide hundreds of users on the same machine a way to configure how their websites are served, without it affecting the others. Customers can configure a lot of details in a restricted shared hosting environment, while never touching the global server configuration.
Every time. It then needs to process these files and reconfigure itself for each of the directories configured in this way. With WordPress websites, things can get really complex. A typical WordPress website can have hundreds of requests from different directories. For each of these resources, Apache has to traverse its entire tree to look for the configuration.
One analysis has shown that a typical WordPress setup, rather common for websites on shared hosts, will include 42 separate. This is just at a web server level. The visitor still needs to wait for the PHP process to execute the entire WordPress call stack to create the database query and give it to MySQL to assemble the web page and send it to the visitor.
Modules — as a feature that allows users to extend web server functionality — exist both in Nginx and Apache. Debian-based distributions have commands that allow enabling and disabling these modules without having to edit any configuration files: a2enmod and a2dismod. The official list of modules that come as part of Apache standard distribution is here and these include things from compression, encryption, logging, redirections to more advanced things like editing requests and responses with advanced syntax.
The server was first created as a scaling tool for the website rambler. It comes in two versions: open source, with BSD-type license , and Nginx Plus , with support and additional enterprise features. After it was released, Nginx was used mostly to serve static files and as a load-balancer or reverse proxy in front of Apache installations.
As the web evolved, and the need to squeeze every last drop of speed and hardware usage efficiency with it, more websites started to replace Apache with Nginx entirely, thanks also to a more mature software.
According to data from w3techs , Nginx market share has been steadily growing, pushing Apache out and dethroning it from the first place:.
This data pertains to overall web servers globally, but if we take sample of the top one million websites, Nginx has been there for some time now:. Netcraft survey suggests that Apache has been overtaken by Nginx in April Nginx does not have a configuration system like Apache so, despite it being a lot more efficient and fast, it is not widely employed with retail hosting providers.
It does not shine in shared environments as Apache does. On the other hand, as we said, by not allowing directory-level configurations, Nginx gains a significant edge over Apache. There is an article on Nginx wiki that compares performance impact:. 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. This may be less flexible than the Apache model, but it does have its own advantages. The most notable improvement over the. For a typical Apache setup that may allow. If one or more. By not allowing directory overrides, Nginx can serve requests faster by doing a single directory lookup and file read for each request assuming that the file is found in the conventional directory structure.
Another advantage is security related. Distributing directory-level configuration access also distributes the responsibility of security to individual users, who may not be trusted to handle this task well.
Ensuring that the administrator maintains control over the entire web server can prevent some security missteps that may occur when access is given to other parties. Keep in mind that it is possible to turn off. How the web server interprets requests and maps them to actual resources on the system is another area where these two servers differ. Apache provides the ability to interpret a request as a physical resource on the filesystem or as a URI location that may need a more abstract evaluation.
Because Apache was designed from the ground up as a web server, the default is usually to interpret requests as filesystem resources. It begins by taking the document root and appending the portion of the request following the host and port number to try to find an actual file. Basically, the filesystem hierarchy is represented on the web as the available document tree. Apache provides a number of alternatives for when the request does not match the underlying filesystem.
For instance, an Alias directive can be used to map to an alternative location. There are also regular expression variants which can be used to apply configuration more flexibly throughout the filesystem. While Apache has the ability to operate on both the underlying filesystem and the webspace, it leans heavily towards filesystem methods. This can be seen in some of the design decisions, including the use of.
The Apache docs themselves warn against using URI-based blocks to restrict access when the request mirrors the underlying filesystem. Nginx was created to be both a web server and a proxy server. Due to the architecture required for these two roles, it works primarily with URIs, translating to the filesystem when necessary. This can be seen in some of the ways that Nginx configuration files are constructed and interpreted.
Nginx does not provide a mechanism for specifying configuration for a filesystem directory and instead parses the URI itself.
For instance, the primary configuration blocks for Nginx are server and location blocks. The server block interprets the host being requested, while the location blocks are responsible for matching portions of the URI that comes after the host and port. At this point, the request is being interpreted as a URI, not as a location on the filesystem. For static files, all requests eventually have to be mapped to a location on the filesystem.
First, Nginx selects the server and location blocks that will handle the request and then combines the document root with the URI, adapting anything necessary according to the configuration specified. This may seem similar, but parsing requests primarily as URIs instead of filesystem locations allows Nginx to more easily function in both web, mail, and proxy server roles.
Nginx is configured simply by laying out how to respond to different request patterns. Nginx does not check the filesystem until it is ready to serve the request, which explains why it does not implement a form of.
Both Nginx and Apache are extensible through module systems, but the way that they work differ significantly. The Apache core is always present, while modules can be turned on or off, adding or removing additional functionality and hooking into the main server. Apache uses this functionality for a large variety tasks. Due to the maturity of the platform, there is an extensive library of modules available.
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. Print [1]Nedelcu, Clement.
Birmingham: Packt Publishing, Print [2]Kholodkov, Valery. Nginx Essentials. User assumes all risk of use, damage, or injury. You agree that we have no liability for any damages. What is Apache? What is Nginx? Difference between Apache and Nginx While both Apache and Nginx are the two major players in the web server business spanning 50 percent of the web traffic over the internet, they are different from each other.
Apache is a open-source HTTP server whereas Nginx is a high-performance asynchronous web server and reverse proxy server. Support, bug fixes, and application development in Apache HTTP server is managed and maintained by a community of users from around the world and coordinated by the Apache Software Foundation. Support and maintenance of Nginx is handled by a company of the same name which was founded in The major difference between the two is the way both handle client requests.
While Apache provides a variety of multiprocessing modules to handle client requests and web traffic, Nginx is so designed to handle multiple client requests simultaneously with minimal hardware resources.
In Apache HTTP server, single thread is associated with only one connection, whereas a single thread in Nginx can handle multiple connections. All the processes are put in an event loop along with other connections and are managed asynchronously.
This process consumes less memory thereby increasing performance. Apache has a multi-threaded architecture which lacks scalability.
Nginx, on the other hand, follows an asynchronous event-driven approach to handle multiple client requests. Its event-driven architecture is so designed to facilitate better performance even under heavy traffic.
Apache serves static content using conventional methods and processes dynamic content natively within the web server itself.
0コメント