Nginx is a software web server that has load management and reverse proxy with open source code. It works with http, https, SMTP, POP3, IMAP or SSL protocols. The focus is mainly on high performance, along with low memory requirements. Nginx is available on Unix-like systems under the BSD, such as UNIX, Linux, but is also available for Solaris, macOS or MS Windows.

Properties of Nginx

The main purpose of Nginx is to rapidly distribute the static content and to enable the maximum distribution of the load among other servers on the basis of set priorities. At the same time, the system is customized to define the backup server to which Nginx can pass the request if the primary server doesn’t provide a response within the specified limit.

Incoming requests are processed asynchronously which is different, for example, from Apache, which uses a fibre or a process system. The typical way of use is that the incoming http or https request primarily tries to find its cache which has both configurable size and storage time. If it finds its cache, it sends the answer straight away.

Otherwise, it turns to one of the servers of the defined set. These servers have a specified priority. If the server doesn’t deliver the response in the specified time, it turns to the standby server.

If possible, the answer is saved to the cache, this allows the following queries to be processed from cache until the set time expires. At the same time, it is possible to set a limit on the number of connections from one IP address, which is a basic defence against DDOS attacks.

Nginx is built on the principle of the modular system, so it is possible to add modules, but it often brings a need of recompilation. One of the module is, for example the GEO location. This module allows to transfer requests to defined servers by the country, or on the contrary, to block the site access from defined countries.

Other useful modules are, for example, redirection modules according to a defined rule set, password security, streaming in FLV or MP4 formats and gzip compression support.

The comparison of Nginx and Apache

Both Nginx and Apache are among the most actively used open-source servers on the internet.

The advantages of using Nginx

  • Less resource demand. Unlike Apache, Nginx doesn’t require such amount of resources and memory.
  • Performance. Nginx can process more than ten thousand simultaneous connections with low memory footprint.
  • Nginx can better deal with static content.
  • Better scalability.
  • More suitable for pages running on VPS.

The disadvantages of using Nginx

  • Worse community support.
  • Smaller number of available modules.

The advantages of using Apache

  • Wider choice of available modules. Although Nginx has available modules for all basic needs, Apache has a wider choice of them.
  • More suitable for use with shared hosting.
  • More frequently used. The fact that Apache server is used more carries with it a wider community and thus a simpler solution to problems and finding tips.
  • It makes the .htaccess file configuration available.
  • Administrative consoles.

The disadvantages of using Apache

  • Resource demand. With a higher load, it uses more RAM than Nginx.
  • Efficiency. It creates a new process for each requirement, that’s why it is less efficient.

When to use Nginx and when Apache

If you are looking for a maximum performance while working with a static content, it’ll be normally better to use Nginx. At the same time, Nginx is a leading solution in scalability, media streaming, VPS hosting or reverse proxy.

Apache is suitable if you need to edit .htaccess file for server configuration, because Nginx doesn’t support this option at all. Apache is also better in the shared hosting environment and offers a control panel that facilitates changes on the server site.