directory

Forward Proxy

A, description,

Give some specific examples

Reverse Proxy

A, description,

Give some specific examples

Reverse proxy configuration tutorial


Forward Proxy

A, description,

The general access process is that the client directly sends a request to the target server and obtains the content. For example, you can enter the corresponding website of Baidu.com, QQ.com, taobao.com, zygxsq.cn/daohang and so on through the browser, then you can directly enter the website of the other party.

When the forward proxy is used, the client sends the request to the proxy server and specifies the target server (the original server), and then the proxy server communicates with the original server, forwarding the requested and obtained content, and then returns it to the client.

The forward proxy is used to hide the real client. The proxy server sends and receives requests for the client, so that the real client is invisible to the server.

Give some specific examples

If your browser cannot access Google directly, you can use a proxy server to help you access Google. This server is called a forward proxy.

② There is also V, which is often used in the office. P. N, is also a similar principle, through the home computer to connect to the company’s proxy server, and then the company’s proxy server to really access the company’s internal data. So everyone’s access will be recorded on the proxy server.

Reverse Proxy

A, description,

Again compared to the general access process above,

In this case, after the reverse proxy is used, the server that receives the request directly is the proxy server, and then the request is forwarded to the server that actually processes the request on the internal network, and the result is returned to the client.

The reverse proxy is used to hide the real server. It sends and receives requests for the server, making the real server invisible to the client. This is usually used when dealing with cross-domain requests. Now basically all large websites have set up reverse proxies.

Give some specific examples

If the company has realized the separation of front and back ends, a server is deployed on the front end, 11.11.11.11, and a lot of interfaces are deployed on the back end, such as a server specializing in order service, 11.11.11.12, a server specializing in single sign-on and JWT,11.11.11.13. A server dedicated to images: 11.11.11.14…… In short, the background has a lot of interfaces, this time, as long as the foreground through a specific prefix, such as the foreground request order service, add /order/geyXXXXX; For login request, add a prefix /login/getXXXXX; /img/getXXXX…… Thus, at the proxy server, requests can be specified to specific other servers by intercepting specific prefixes, thus implementing reverse proxies and cross-domain requests

In simple terms, the proxy for the client is a forward proxy, and the proxy for the server is a reverse proxy.

Reverse proxy configuration tutorial

Upstream (upstream) is used to configure the nginx reverse proxy

Upstream order{server 11.11.11.12:8080; upstream order{server 11.11.11.12:8080; Server 11.11.11.22:8080; }Copy the code

Similarly, configure the login server, image server, and so on

Upstream login {server 11.11.11.13:8080; Server 11.11.11.23:8080; } upstream img{server 11.11.11.14:8080; Server 11.11.11.24:8080; }Copy the code

You can then reversely proxy the request to the specified server by listening for different prefixes

. server{ location /order { proxy_pass http://order; break; The HTTP header is forwarded to the backend application. Otherwise, your backend application server will receive the nginx proxy address instead of the client's IP address. Proxy_set_header Host $Host; proxy_set_header X-Real-IP $remote_addr; } } location /login { proxy_pass http://login; break; } location /img { proxy_pass http://img; break; }}...Copy the code

Proxy_pass http://login and proxy_pass http://login/ have one more /, but these are two very big differences

location /login { proxy_pass http://login; \ break; }

If it is proxy_pass http://login, it is the request link on the complete concatenation, if it is proxy_pass http://login/, it is the login to remove, the following to the concatenation

For a simple example, let’s say I’m requesting /login/getUserxx on the front end

Through the reverse proxy, the actual request is 11.11.11.13:8080 / login/getUserxx or 1.11.11.23:8080 / login/getUserxx

location /login { proxy_pass http://login; \ break; }

But with the following belt/reverse proxy, the actual request is 11.11.11.13:8080 / getUserxx or 1.11.11.23:8080 / getUserxx

location /login {

proxy_pass http://login/ ;

break;

}

Of course, this is just a brief introduction to the basic configuration of reverse proxy, there are many, many configurations, you can also search the Internet, other big guys tutorials


Refer to the article

Mp.weixin.qq.com/s/hjqlpr3ev…

www.cnblogs.com/mrlinfeng/p…

Blog.csdn.net/martingpf/a…

Blog.csdn.net/qq_29298577…

Thanks for the original author’s sharing, so that technical people can solve the problem faster