They are all using nginx. Do you really know its application scenarios?


You must have heard of nginx. If you haven’t heard of it, you must have heard of its “peer” Apache!

The production of nginx

Nginx, like Apache, is a web server. Based on the rest architecture style, the uniform resources identifier (URI) or uniform resources locator (URL) is used as the communication basis to provide various network services through HTTP protocol.

However, at the beginning of the design, these servers were limited by the environment at that time, such as the size of users, network bandwidth, product characteristics and so on, and their positioning and development were not the same. This also makes each web server has its own distinct characteristics.

Apache has a long history of development, and it is the world’s largest server without dispute. It has many advantages: stable, open source, cross platform and so on.

It has been around for a long time. The Internet industry is far less developed than it is now. So it was designed to be a heavyweight.

It does not support highly concurrent servers. Running tens of thousands of concurrent accesses on Apache will cause the server to consume a lot of memory.

The switching between processes or threads by the operating system also consumes a lot of CPU resources, resulting in the reduction of the average response speed of HTTP requests.

All these make Apache impossible to be a high-performance web server, and nginx, a lightweight and high concurrency server, came into being.

Igor sysoev, a Russian engineer, developed nginx in C while working for rambler media.

As a web server, nginx has been providing excellent and stable services for rambler media. Then, Igor sysoev will open source nginx code and grant free software license.

Because of the following points, nginx is on fire:

Nginx uses an event driven architecture to support millions of TCP connections.

A high degree of modularity and free software license make third-party modules emerge in an endless stream (this is an era of open source).

Nginx is a cross platform server, which can run on Linux, windows, FreeBSD, Solaris, AIX, Mac OS and other operating systems.

These excellent designs bring great stability.

Where to use nginx

Nginx is a free, open source, high-performance HTTP server and reverse proxy server, as well as IMAP, POP3 and SMTP proxy server.

Nginx can be used as an HTTP server for website publishing, and nginx can be used as a reverse proxy for load balancing.

About agency

When it comes to agency, first of all, we need to define a concept. The so-called agency is a representative and a channel. At this time, it involves two roles, one is the role of the agent, and the other is the role of the target.

The process in which the agent accesses the target role to complete some tasks is called the agent operation process. Just like the exclusive store in life, when a customer buys a pair of shoes in the adidas exclusive store, the exclusive store is the agent, the agent is the adidas manufacturer, and the target role is the user.

Forward agency

Before talking about reverse proxy, let’s take a look at forward proxy. Forward proxy is also the most common proxy mode. We will explain the processing mode of forward proxy from two aspects: software and life.

In today’s network environment, if we want to visit some foreign websites due to technical needs, you will find that there is no way for us to visit a foreign website through the browser.

At this time, you may use an operation FQ to access, and the main way of FQ is to find one that can be accessedSource code transactionForeign website proxy server, we will send the request to the proxy server, the proxy server to visit the foreign website, and then will visit the data to us!

The above-mentioned proxy mode is called forward proxy. The biggest feature of forward proxy is that the client is very clear about the server address to be accessed; the server only knows which proxy server the request comes from, but not which specific client; the forward proxy mode shields or hides the real client information.

Let’s take a look at a schematic diagram (I frame the client and the forward proxy together, and they belong to the same environment. I will introduce them later)

The client must set up a forward proxy server. Of course, the premise is to know the IP address of the forward proxy server and the port of the proxy program. To sum up: the forward proxy, “it represents the client”, is a server located between the client and the original server. In order to get the content from the original server, the client sends a request to the proxy 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. The client must make some special settings to use the forward proxy.

Purpose of forward proxy:

Access to previously inaccessible resources, such as Google.

Cache can be done to speed up access to resources.

The client access authorization, online authentication.

Agents can record user access records (Internet behavior management) and hide user information.

Reverse proxy

To understand what is forward proxy, let’s continue to look at the processing methods of reverse proxy. For example, the number of visitors who connect to the website at the same time every day has exploded, and a single server is far from meeting the people’s growing desire to buy.

At this point, there is a familiar term: distributed deployment; that is, to solve the problem of access restrictions by deploying multiple servers.

Most of the functions of a certain treasure website are realized by using nginx as reverse proxy directly, and after encapsulating nginx and other components, it has a big name: Tengine.

Through the above diagram, you can see clearly that after the nginx server receives the requests sent by multiple clients to the server, it distributes them to the back-end business processing server for processing according to certain rules.

At this time, the source of the request, that is, the client, is clear, but it is not clear which server handles the request. Nginx plays a reverse proxy role.

The client is not aware of the existence of the agent, the reverse agent is transparent to the outside, visitors do not know that they are visiting an agent. Because the client does not need any configuration to access.

Reverse proxy, “it represents the server”, which is mainly used in the case of distributed deployment of server cluster. Reverse proxy hides the information of server.

The role of reverse proxy:

To ensure the security of Intranet, reverse proxy is usually used as the access address of public network, and web server is intranet.

Load balancing, through the reverse proxy server to optimize the load of the website.

Recommended Today

Third party calls wechat payment interface

Step one: preparation 1. Wechat payment interface can only be called if the developer qualification has been authenticated on wechat open platform, so the first thing is to authenticate. It’s very simple, but wechat will charge 300 yuan for audit 2. Set payment directory Login wechat payment merchant platform( pay.weixin.qq . com) — > Product […]