How Nginx forward proxy-proxy Internet

1 Introduction

nginxIt can 反向代理be used not only to do it , but also to do 正向代理( 透明代理, 代理上网),

Here you can browse the nginx reverse proxy

2. Reverse proxy

External device through 网关access to content on the back of the gateway server, 网关played a 反向代理feature we usually accessed remotely through a browser web服务器mostly are implemented.

3. Forward proxy

It is the reverse of the above process. As we usually say 上网代理, users in the local area network access external networks through the gateway as a proxy.

4. Comparative analysis of forward proxy and reverse proxy

Both of them have three common roles:

请求者 代理者 实际目标

If cross-domain problems are encountered during local development, we do proxy forwarding:

/api/items=> http://localhost:3000/api/items(Forward) =>http://localhost:7777/api/items


This kind of forwarding is called 正向代理=> 请求者&代理者in the same domain ( 被服务端) and the target is on another server ( 服务端)

请求者Usually browser

代理者http://localhost:3000

实际目标 http://localhost:7777


Reverse proxy

请求者Is a domain ( 被服务端) 代理&目标is another group ( 服务端)

Most of the actual local development belongs to 正向代理. If the code is compiled and dropped on the server, this time will inevitably involve cross-domain. If the front-end code is server1accessed, and the back-end code is server2accessed, the browser and them are separated, this time is the 反向代理mode .

Usually develop when the browser is also the same broker on one server, are generally developed 正向代理, and after the release, the browser will not be together, that is 反向代理the.

5. Nginx proxy Internet access

nginxIt can also realize the function of proxy surfing, the configuration is as follows:

user www;
worker_processes 1;
error_log /var/log/nginx/error.log debug;

events {
    
    
	use epoll;
	worker_connections 1024;
}

http {
    
    
	resolver 8.8.8.8;
	server {
    
    
		listen 8088;
		location / {
    
    
			proxy_pass http://$http_host$request_uri;
		}
	}
}

nginxThere are three key points to pay attention to to realize proxy Internet access, and the rest of the configuration is the nginxsame as ordinary
1. Increase dnsanalysisresolver

2. Increase the no server_namenameserver

3. proxy_passInstructions

6. Implementation steps

1. Fill in the following configuration to the http scope of your configuration file

    resolver 8.8.8.8;
	server {
    
    
		listen 8088;
		location / {
    
    
			proxy_pass http://$http_host$request_uri;
		}
	}

2. Restart nginx to make the configuration file effective

nginx -s reload

3. Set up ie proxy
Insert picture description here

4. You can use the proxy to go online

You can visit http://ip.quancha.cn to check whether the proxy is effective. After
using the nginxproxy to go online

Insert picture description here

Before using nginx proxy to go online

Insert picture description here



(To be added later)

Guess you like

Origin blog.csdn.net/u013946061/article/details/107739532