This is the 19th day of my participation in the Genwen Challenge

background

I took some notes on a previous project that used some of Nginx’s advanced features, so I’m going to put this series together.

Nginx

Forward and reverse proxies

Forward agent

  • A forward proxy server is a server that sits between the client and the original server. To get content from the original server, the client sends a request to the proxy server and specifies the target (the original server). The proxy then forwards the request to the original server and returns the obtained content to the client
  • At ordinary times, the proxy server of the foreign website is to use the forward proxy
  • The feature of forward proxy is that the user knows exactly which web site to visit

The reverse proxy

  • A reverse proxy receives external requests as a proxy server, forwards the requests to the data server on the internal network, and returns the request results to the requesting client
  • The characteristic of reverse proxy is that when the request is sent to the proxy server, the client does not know which data server is providing the data that is finally obtained

The difference between forward and reverse proxies

  1. Different proxy objects
  • The forward proxy, the proxy client, the server does not know which client actually initiated the request
  • The reverse proxy, the proxy server, the client does not know the server that actually provides the service
  1. Application scenarios of forward proxy
  • Access previously inaccessible resources
  • Used as a cache to speed up access
  • Authorize client access and authenticate Internet access
  • The proxy can record user access records (online behavior management) and hide user information externally
  1. Application scenarios of reverse proxy
  • Protecting Intranet Security
  • Load balancing
  • Caching, reduce the strain on the server

Nginx profile

  • Nginx is a lightweight HTTP server and reverse proxy server and E-mail (IMAP/POP3) proxy server
  • Nginx has a low memory footprint and high concurrency
  • Nginx is written in an event-driven manner and has very good performance
  • Nginx is a very efficient reverse proxy, load balancing
  • Nginx is known for its stability, rich module libraries, flexible configuration, and low system resource consumption
  • Nginx responds to static pages very quickly
  • There is thorough support for the proxy and rewrite modules, as well as mod_fcgi, SSL, and vhosts

Nginx characteristics

As an HTTP server, Nginx has the following basic features:

  • Handle static files, indexed files, and automatic indexing; Open the file descriptor buffer
  • Caches free reverse proxy acceleration, simple load balancing and fault tolerance
  • FastCGI, simple load balancing and fault tolerance
  • Modular structure: including Gzipping, Byte ranges,chunked responses, and SSI-filter filter; If FastCGI or another proxy server processes multiple Ssis in a single page, the processing can run in parallel without waiting for each other
  • Supports SSL and TLSSNI
  • Nginx was developed specifically for performance optimization. It supports the kernel Poll model and has been reported to support up to 50,000 concurrent connections
  • Nginx has a very high stability. Nginx adopts a phased resource allocation technique, which makes its CPU and memory usage very low. Nginx officially maintains 10000 inactive connections, which only takes up 2.5M of memory
  • Nginx supports hot deployment, enabling business applications to be upgraded without interruption of service
  • Nginx uses the master-slave model to take full advantage of SMP, reduce the blocking delay of worker processes in disk I/O, and limit the number of connections per process when using select()/poll() calls
  • Nginx modules are easy to extend, especially with powerful Upstream and Filter chains, which provide a good basis for writing modules such as the Reverse proxy to communicate with other servers. The Filter chain can take the output of the previous Filter as the input of the current Filter, similar to the Unix pipeline

Nginx common commands

Start the Nginx

nginx
Copy the code

Stop the Nginx service immediately

nginx -s stop
Copy the code

Reload the configuration file

nginx -s reload
Copy the code

Smooth stops the Nginx service

nginx -s quit
Copy the code

Test whether the configuration file is correct

nginx -t
Copy the code

Nginx version information is displayed

nginx -v
Copy the code

Displays Nginx version information, compiler and configuration parameter information

nginx -V
Copy the code

Nginx running mode

  • Nginx runs in the background as a daemon on a Unix system, including a master process and multiple worker processes
  • You can manually turn off the Nginx background mode to allow Nginx to run in the foreground, and configure the master process to cancel Nginx so that Nginx runs as a single process. Turning off background mode is generally used for debugging, not in production
  • Nginx works in multi-process mode by default, but it also supports multi-thread mode. Currently, multi-process mode is the mainstream