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.
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.
Both Nginx and Apache are among the most actively used open-source servers on the internet.
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.