preface

The article you see now is the third version of the revision.

After my boss read this article, the evaluation is: it is well written, the sentence is smooth, typesetting is ok, but what reverse proxy is still not clear? So I tried to explain “forward proxy” and “reverse proxy” to non-IT workers.

I will try to explain the concept of “agency” to the general public. Explain “forward proxy” and “reverse proxy” from a professional perspective.

Conceptual instantiation

Before I get to the idea of agency let me make an analogy. That’s how I explained it to my boss.

In the absence of thoughts, she suddenly asked me if I had eaten for dinner? Isn’t that a good example?

After explaining for so long, I don’t know whether I really understand, or because I am too sleepy. But I have money for meat.

Let’s take a closer look at “forward proxies” and “reverse proxies.”

concept

Look at the illustration first to get a general idea.

Forward Proxy:

To get content from the original server, the client sends a request to the agent and specifies the target (the original server). The agent then forwards the request to the original server and returns the content to the client. The client can use the forward proxy.

Reverse Proxy:

A proxy server receives the Internet connection request, forwards the request to the Intranet server, and returns the result to the Internet client. In this case, the proxy server acts as a reverse proxy server.

Let me distill the characteristics of each.

The characteristics of

Forward agent

  1. Acting customers;
  2. Hide the real client, send and receive requests for the client, so that the real client is invisible to the server;
  3. All users on a LAN may be forward propped by a server that handles HTTP requests.
  4. The forward proxy server communicates with the server.

The reverse proxy

  1. Proxy server;
  2. Hide the real server, send and receive requests for the server, so that the real server is invisible to the client;
  3. Load balancing servers that distribute user requests to idle servers;
  4. This means that the user communicates with the load balancing server directly, that is, the user obtains the IP address of the load balancing server when resolving the server domain name.

In common

  1. Both serve as the middle layer between the server and the client
  2. Both can enhance Intranet security and prevent Web attacks
  3. Can do caching mechanism, improve access speed

The difference between

  1. The forward proxy is actually the proxy of the client, and the reverse proxy is the proxy of the server.
  2. In forward proxy, the server does not know who the real client is. In a reverse proxy, the client does not know who the real server is.
  3. Different functions. Forward proxy is mainly used to solve the access restriction problem. Reverse proxy provides load balancing and security protection.

Having said that, let’s talk about the application scenarios of agents at work.

The practical application

Over the Wall software – forward proxy

We know that you cannot access www.google.com in China, because the access is normally restricted by THE GFW.

But you still want to use Google to scientific Internet access, this time we need some agents (over the wall software) to help us to request www.google.com, the agent will return the response results to you.

The GFW is mainly used to analyze and filter the traffic between networks inside and outside China. In other words, it can not only restrict domestic users from accessing certain foreign sites, but also restrict foreign users from accessing domestic sites. When we say “walled”, we mean that access is restricted by the GFW. “Scaling the wall,” as the name suggests, is breaking through the limits of the GFW.

Nginx server — Reverse proxy

The Nginx server has many functions, such as reverse proxy, load balancing, static resource server, and so on.

The client could have accessed the server directly through HTTP, but we can add an Nginx server in the middle. The client requests the Nginx server, and the Nginx server requests the application server, and then returns the results to the client, which is the reverse proxy server.

Configure the reverse proxy in the configuration of the virtual host

# Virtual host configuration
server {
    listen 8080;                         Listen to the portServer_name 192.168.1.1.Configure the access domain name
    root  /data/toor;                    # site root directory
    error_page 502 404 /page/404.html;   # error page
    location ^~ /api/  {                        Use the/API/proxy proxy_pass valueProxy_pass http://192.168.20.1:8080;HTTP address of the proxied application server}}Copy the code

The previous simple configuration can implement the reverse proxy function.

Of course reverse proxies can also handle cross-domain problems.

Vue-cli uses http-proxy-middleware to configure proxy servers.

So we can use proxyTable, set the address mapping table. That is to use the proxyTable attribute for related configuration to solve cross-domain problems. The configuration is as follows:

. proxyTable: {'/weixin': {
        target: 'http://192.168.20.1:8080/'// Interface domain name secure:false// If the interface is HTTPS, you need to configure the parameter changeOrigin:true// If the interface is cross-domain, you need to configure this parameter pathRewrite: {'^/weixin': ' '}}},...Copy the code

Configure load balancing

Upstream represents the load server pool and defines the name myUpstream my {server 192.168.2.1:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.2:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.3:8080 weight=1 max_fails=2 fail_timeout=30s; Server 192.168.2.4:8080 weight=1 max_fails=2 fail_timeout=30s;If two attempts fail within 30 seconds, the host is considered unavailable
  }
Copy the code

Load balancing refers to request/data polling spread over multiple servers. The key to load balancing is evenness.

You can also use ip-hash to allocate requests to a fixed server based on the hash value of the client IP address.

In addition, the hardware configuration of the server may be different and the configured server can handle more requests, which can be controlled by the weight parameter.

Vue related article output plan

Recently, some friends always ask me questions about Vue, so I will output 9 vUe-related articles, hoping to be of some help to you. I will keep it updated every 7 to 10 days.

  1. The process by which Vuex is injected into the Vue lifecycle
  2. 【 Front-end dictionary 】 Analysis of Vue responsive principle
  3. [Front-end dictionary] Patch between old and new VNodes
  4. How to develop functional components and upload NPM
  5. Optimize your Vue project in these areas
  6. 【 Front-end Dictionary 】 From vue-router design to front-end routing development
  7. How to use Webpack correctly in a project
  8. Vue server render
  9. How to choose between Axios and Fetch

I suggest you pay attention to my public number, the first time you can receive the latest article.

If you want to join a group, you can also add a smart robot that automatically pulls you into the group:

Portal of popular articles

  1. Solution to the rolling penetration problem
  2. Comparison of 5 implementations of rolling top suction (Performance Upgrade version)
  3. 9 CSS Tricks to Improve your happiness
  4. Share 8 interesting and useful apis
  5. [Front-end dictionary] What is involved in caching from entering URL to rendering (very detailed)