“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021.”

background

Nginx (” Engine X “) is a high-performance [HTTP] and [reverse proxy] [WEB server], as well as a [POP3/SMTP/IMAP proxy server], written in C by Igor Sessoyev (Russian), The first release of Nginx was version 0.1.0 on October 4, 2004. It is also worth mentioning that Igor Sassoyev has opened the source code of Nginx, which also provides a good guarantee for the development of Nginx.

1. WEB server:

WEB Server is also called WEB Server, English name WEB Server, the main function is to provide users with online information browsing services.

2. HTTP:

HTTP is short for Hypertext Transfer Protocol, which is used to transfer hypertext from WEB servers to local browsers. It is also the most widely used network protocol on the Internet. HTTP is a standard for client and server requests and responses. The client is the end user and the server is the website. By using a Web browser, Web crawler, or other tools, the client initiates an HTTP request to a specified port on the server.

3. The POP3 / SMTP, IMAP:

POP3(Post Office Protocol 3) The third version of the Post office Protocol,

SMTP(Simple Mail Transfer Protocol)

Internet Mail Access Protocol (IMAP)

Nginx can also be used as an E-mail proxy server.

4. Reverse proxy

Forward proxy:

Reverse proxy:

Common Server Comparison

Tomcat

Tomcat is a Web application software that runs servlets and JSP. With advanced technology, stable performance and open source code, Tomcat is deeply loved by Java enthusiasts and recognized by some software developers, making it a popular Web application server at present. But Tomcat is by nature a heavyweight Web server that is weak on static files and high concurrency.

Apache

Apache has a long history and has had a great run. From the chart above, we can see that it was the no.1 server in market share until about 2014. Apache has many advantages, such as stability, open source, cross-platform, etc. But it’s been around for so long that it was designed to be a heavyweight Web server that didn’t support high concurrency at a time when the Internet was much smaller than it is today. On the Apache server, if tens of thousands of concurrent HTTP requests are accessed at the same time, a large amount of memory will be consumed on the server. Switching between hundreds of Apache processes by the operating system kernel will also consume a large amount of CPU resources and reduce the average response speed of HTTP requests. All of these make It impossible for Apache to become a high-performance Web server. This led to the emergence of Lighttpd and Nginx.

The advantages of Nginx

(1) Faster, higher concurrency

Nginx responds faster than other Web servers for single requests or high concurrent requests. On the one hand, under normal circumstances, a single request will get a faster response, on the other hand, during peak times (such as tens of thousands of concurrent requests), Nginx will respond to requests faster than other Web servers. The reason for Nginx’s high concurrency and performance is its underlying implementation of multiprocess and I/O multiplexing (epoll).

(2) Simple configuration and strong expansibility

Nginx is designed to be extremely extensible and is itself made up of modules whose use can be added through configuration files. These modules can be officially provided or provided by third parties. If necessary, you can develop custom modules to serve your own business features.

(3) High reliability

Nginx runs in multi-process mode, in which there is a master process and N more than worker processes. The number of worker processes can be set manually. Each worker process provides services independently. Quickly go to “pull up” the new worker process to serve.

(4) hot deployment

Nginx also provides hot deployment, which allows Nginx to upgrade files, update configurations, and replace log files without stopping Nginx.

(5) Low cost, BSD license

BSD is an open source license. There are many open source licenses in the world. Six popular licenses are GPL, BSD, MIT, Mozilla, Apache, and LGPL. What are the differences between these six types? We can explain them by the following picture:

Nginx itself is open source, so not only can we use Nginx freely for commercial applications, but we can also directly modify the Nginx source code in projects to customize our own special requirements. These are the reasons why Nginx attracts countless developers who continue to contribute their brains and youth to Nginx. OpenRestry [Nginx+Lua] Tengine

Nginx features and common functions

The basic functional services provided by Nginx can be roughly classified into “basic HTTP services”, “advanced HTTP services” and “mail services”.

Basic HTTP service

Nginx can provide basic HTTP services, can be used as HTTP proxy server and reverse proxy server, support accelerated access through cache, can complete simple load balancing and fault tolerance, support packet filtering function, support SSL, etc.

  • Process static files, process indexed files, and support automatic indexing;
  • Provide reverse proxy server, and can use cache plus reverse proxy, load balancing and fault tolerance;
  • Provide cache mechanism for FastCGI, memcached and other services, and complete load balancing and fault tolerance at the same time;
  • Use the modularity features of Nginx to provide filter functionality. Basic Nginx filters include Gzip compression, ranges support, chunked responses, XSLT, SSI, and image scaling. For pages with multiple Ssis, the SSI filter can be processed in parallel via FastCGI or reverse proxy.
  • Supports SSL over HTTP.
  • Support HTTP/2 based on weighted and dependent priorities

Advanced HTTP service

  • Support virtual host Settings based on name and IP address
  • Support for keep-alive mode and PipeLined model connections in HTTP/1.0
  • Custom access log formats, cached log writes, and fast log rotation.
  • Provides 3xx to 5XX error code redirection
  • Support for the Rewrite module extension
  • Supports reloading configurations and online upgrades without interrupting ongoing requests
  • Network Monitoring
  • Support FLV and MP4 streaming media transmission

The mail service

Nginx provides mail proxy service as one of its basic development requirements, including the following features:

  • Supports the IMPA/POP3 proxy service
  • Supports the internal SMTP proxy service

Nginx common function modules

Static resource deployment Rewrite address Rewrite regular expression reverse proxy load balancing polling, weighted polling, IP_hash, URl_hash, and Fair Web cache deployment High availability environment User authentication module...Copy the code

The core components of Nginx

Nginx binary executable file nginx.conf configuration file error.log Records error logs Access. log Records access logsCopy the code