Nginx most basic teaching

Original article in Public number: ape Zhou Xiansen program. This platform is not updated regularly, like my article, I welcome attention to the micro-channel public number.
file

Nginx is a kind of the same with Apache WEB server. Based on the REST architectural style, uniform resource descriptor URI, or Uniform Resource Locator (URL) as a communication basis, providing a variety of network services through the HTTP protocol. However, these servers by the time the user scale, network bandwidth, and other characteristics of the product early in the design limitations and their positioning and development are different. It also makes various WEB servers have their own distinctive features. Apache long period of development, it has many advantages: a stable, open source, cross-platform, and so on. It is designed to be a heavyweight WEB server, but it does not support high-concurrency. Concurrent access on Apache, causes the server to consume a lot of memory. Its operating system to switch between processes or threads also consumes a lot of CPU resources, resulting in lower average response rate of HTTP requests. This time lightweight high-concurrency server Nginx came into being.

Why would Nginx popular Internet it? It is because of the large notable feature Nginx few exist:

  • Nginx based event-driven architecture, so that it can support millions-level TCP connection

  • High degree of modularity and software licenses are free of third-party modules after another (which is an open source era ah ~)

  • Nginx is a cross-platform server that can run on Linux, Windows, FreeBSD, Solaris, AIX, Mac OS and other operating systems, these outstanding design brings great stability

As we all know, Nginx is a free, open-source, high-performance HTTP server and reverse proxy server; also a IMAP, POP3, SMTP proxy server; Nginx can publish treatment site as an HTTP server, Nginx can be used as additional reverse proxy load balancing to achieve. Talking agent, the agent is divided into forward and reverse proxy.

Forward Proxy

Forward proxy is everyone most contact with the agency model, then what is it forward proxy? We all know that Google is not accessible in the country is normal, but sometimes we need time because of technical problems to access Google, we will first find a proxy server can access Google, we will send the request to the proxy server, proxy server to access Google, then access to the data is returned to us, such a process is to forward proxy.

Forward proxy features

Forward proxy biggest feature is the client need to clearly know the address of the server to be accessed, Google servers only clear from the request which proxy server, but do not know which particular client from the forward proxy can hide specific information on real clients.
file

The client must be set up forward proxy server, but also need to know the IP address and port agent forward proxy server. Can be summed up forward proxy is a proxy of the client, is a server located between the client and Google's servers, in order to obtain data from Google's servers, the client sends a request and specify the target (Google servers) to the proxy server, the proxy server to transmit the request to the original and the obtained data is returned to the client.

Forward proxy to use:

  • Visit the Web site inaccessible abroad

  • Do caching, to accelerate access to resources

  • For client access licensing, Internet authentication

  • Proxy can record user access records (access management), external users to hide information

Reverse Proxy

Then what is the forward proxy, we are going to look at what is called a reverse proxy, if our website daily visits reached a certain limit, a single server is far meet our daily needs, this time we first think of a distributed deployment. The number of access restrictions to solve the problem by deploying multiple servers, and then we actually function mostly by Nginx reverse proxy to achieve. We can look:
file

Reverse Proxy features

We can clearly see, the plurality of the client to the server sends a request, Nginx server after receiving the request, according to certain rules are forwarded to a different server for business logic. At this point the client from which the request is certain, but the request was not clear which server processes, Nginx play is a reverse proxy role. Can be understood, the external reverse proxy is transparent, accessible to visitors do not know they are a proxy. Reverse proxy server proxy is mainly used in the case of a distributed server cluster deployment, reverse proxy server to hide the information.

Use reverse proxy:

  • Ensure security within the network, usually as a reverse proxy to access the public network address, Web servers within the network

  • Load balancing, to optimize the loading site through reverse proxy server

Forward Proxy and Reverse Proxy difference

  • In the forward proxy to hide the source of client information requests;

  • In the reverse proxy, the hidden server requests specific information processing;

file

Load Balancing

Nginx now plays the role of a reverse proxy, which is based on a request basis for the distribution of what kind of rules? Whether the rules can control the distribution of it? Load is distributed to different rules server to handle in a balanced rules according to certain rules. The server processes the received request in accordance with the distribution rule, referred to as load balancing.

Nginx supports load balancing scheduling algorithm is as follows:

  • Polling weight (default): received request individually allocated in the order of requests to different backend servers, if during use, one server goes down, Nginx automatically removed out of the server queue, request receiving without It will be affected in any way. In this manner, a different set of back-end servers to a weight value, the greater the weight data, the greater the chance is assigned to the server request.

  • ip_hash: ip every request hash result in accordance with the client initiating the match, this algorithm always a fixed client ip address to access the same backend server.

  • fair: intelligently scheduling algorithms, dynamic response time of the request of the backend server equalizing distribution, a high probability of response to short time high processing efficiency of the server assigned to the request, the response time is less long low efficiency server assigned to the request.

  • url_hash: According to hash url to access the results of the allocation request, each request url will point to a server back-end fixed, can improve cache efficiency as in the case of a static Nginx server.

note:

  • Nginx default does not support fair algorithm, if you want to use this scheduling algorithm, you need to install upstream_fair module.

  • Nginx does not support url_hash default scheduling algorithms, you want to use, then you need to install Nginx of hash packages.

As a user of Nginx, in the preparation of the profile certainly had problems, you may often need to spend a lot of time in the configuration file written above. So the next introduce a way to quickly generate online sites Nginx configuration file:

https://nginxconfig.io/

The site supports http, https, php, python, Node, cache, logs and other configuration options, you can generate Nginx configuration files online. And it is extremely simple to use, just fill in the corresponding demand in the site, you can generate a key configuration file.
file

Parameter Description:

  • Domain: binding domain
  • Path: root directory where
  • Document root: the actual project name in the root directory
  • Redirect subdomains: If you visit * .niyueling.cn will redirect Jump to niyueling.cn

Then in the following nginx can generate the corresponding profile. We can download the zip package or copied directly replace our configuration file:
file

Then replace the end of the nginx server configuration file, using the nginx -t command to test whether a file exists problem, no problem if the configuration file, use nginx -s reload command to restart the server. Before replacing in order to ensure there are no surprises, it is best to do a backup of the configuration file in advance.

If you like my articles, my personal welcome attention to public numbers: The program ape Zhouxian Sen.
file

Guess you like

Origin www.cnblogs.com/niyueling/p/11563089.html