Nginx Installation and Configuration Guide: Create a Fast and Efficient Web Server

According to W3Tech, Apache was the most widely used web server in 2016, with over 50% market share among all website operators. However, if you take a different perspective on these numbers and consider only the top 10,000 most visited sites, it paints a different picture: only about 30% of these sites use server technology from 1995. For the top 1,000 commonly used servers, that number shrinks to just 27%.

This number can partly be explained by the high number of running Google web servers (around 10%), on which all Google pages are running. However, another reason can be attributed to the rapid rise of the Russian web server Nginx. As recently as 2010, Nginx was just one of many Apache alternatives, with a market share hovering around a measly 4%. Today, BSD-licensed software is currently being used in every other Web project in the top 10,000 and 1,000, respectively.

Nginx installation and setup

What is Nginx?

Russian software engineer Igor Sysoev was the main force behind the 2004 release of the server software. As is the case today, the main focus back then was to develop an exceptionally high performing server capable of serving as many clients as possible without using too many resources. Due to the server's growing popularity, Sysoev founded NGINX Inc. in 2011 and has been responsible for the continued development of the software since then. In addition to the free standard version, the company also offers NGINX plus, a paid option with support and additional features such as improved load balancing.

Like Apache, NGINX is built modularly. This means that many of its different features are available through corresponding modules, which can be activated or deactivated by administrators. Here is a list of some of the features available to you:

  • Application Acceleration: Make Content Display Faster

  • Reverse Proxy: Allows NGINX to act as a reverse proxy for web acceleration purposes (HTTP, TCP, UDP) or as an email proxy (MAP, POP3, SMTP)

  • TLS encryption: for secure data transmission

  • Bandwidth management: provide optimal bandwidth for all services

  • Load balancing: reduce the burden on the main server by redirecting requests

  • Provides high-performance video streaming when streaming MP4 and FLV media.

Apache opens a new thread or process for each client request, while Nginx server operates in an event-oriented manner. This allows requests to be processed asynchronously, saving working memory and time. The server software is also supported on a range of operating systems, including numerous Unix/Linux variants, including Mac OS and Windows Server.

Install and configure Nginx

Those who opted for the plus addition will go through the installation process with Nginx support. Typically, however, the installation is done according to the notorious pattern of the package manager, as most Linux distributions include Nginx packages in their repositories by default. In case of package loss, you can quickly and easily download the source code from the Nginx official website (click to visit). In the following steps, Popeye will show you how to install and configure a web server under Linux.

1. Update the package manager with the following command so that your system reverts to the latest version of the Nginx package after installation:

 
 

1
2

sudo apt-get update
sudo apt-get install nginx

2. Nginx usually starts immediately after the first step. In order to check whether the software is running normally, just call out the Nginx login page through the server domain name or public network IP address in the browser.

3. Everything needed to configure Nginx can be found in the directory /etc/nginx or in the central configuration file nginx.conf. Whenever you end up making changes to this file, you will need to restart the server using one of the following two commands in order for the changes to be accepted:

 
 

1
2

sudo service nginx reload
sudo service nginx restart

4. The syntax of the configuration file has the following characteristics:

Settings: All settings start with the corresponding variable name. Using spaces, one or more parameters can be added - these parameters are terminated with a semicolon.

 
 

1

worker_connections 768;

Main settings: some settings, like event variables, contain parameters, and then you can represent settings with their own parameters. These subdirectives contain braces ({}).

 
 

1
2
3
4

events {
  worker_connections 768;
  multi_accept on;
}

Tags (#): These are disabled directives, commented out with tags. Removing this symbol activates the setting again. So in the case of the configuration below...

 
 

1

# multi_accept on;

The option to accept multiple clients simultaneously has been disabled.

Tabs and multiple spaces: Nginx interprets tabs set and spaces repeated as one space. When configuring Nginx, you can take advantage of this aspect to ensure that your configuration files are easy to read and structured.

5. More information about the individual modules and an Nginx tutorial for setting up a web or proxy server based on the server software can be found in the provider's documentation below.

What makes Nginx so popular

There are many reasons why Nginx is growing in popularity. First, Web server software is in tune with the current requirements of many Web projects. This is because Nginx not only achieves top-notch results when handling high volumes of client requests; it also operates in an extremely efficient manner, making this software the perfect solution for many mobile data connections with limited performance. As a website operator, Nginx supports you by delivering content quickly to all users, including those on mobile devices.

What's more, the open-source product from the Russian development team has won many users with the flexibility the software offers. In addition to its classic HTTP web server options, Nginx also offers convincing performance in reverse proxy tasks such as acting as an email proxy server or load balancer.

Despite all these advantages, Nginx is not a panacea for server solutions: shared hosting controlled via password-protected areas or internal redirects proves to be very difficult to set up. Such partials and overrides can only be created in a central configuration file and implemented by restarting the server. After that, any errors that occur will affect all participants of the shared hosting instance. This is where Apache still comes in handy, since individual settings can be recorded in separate .htaccess files.

 

Guess you like

Origin blog.csdn.net/winkexin/article/details/131487200