nginx forward proxy, reverse proxy load balancing

First, what is the forward proxy and reverse proxy?
1, forward proxy
Examples: Client (PC) X can not directly access the LAN resources (server) directly through the Internet or an intranet, but the client can directly access a proxy server, but the proxy server can access resources to X PC can not access ,
so we configure proxy server address on the PC, PC to send the request to the proxy server, proxy server to allow access to resources X, X proxy access the resources back to the PC, so as to solve the problem can not be accessed.

Forward Proxy: Client direct traffic to third-party software, or connection to ***, access servers, instead of directly accessing the server.

Traffic flow direction: the real machine -> proxy server.

Forward proxy uses:
resources (1) access to the original can not be accessed, such as Google
(2) can do caching, to accelerate access to resources
(3) access authorization to the client, Internet authentication
(4) proxy can record user access records ( Internet behavior management), external users to hide information

nginx forward proxy, reverse proxy load balancing

2, the reverse proxy
returned to the client (PC) requests resources X, X to obtain resources from the PC and can not feel the presence of a reverse proxy server, the reverse proxy server is transparent to the PC, PC does not need to: Examples any configuration.

Reverse Proxy: server-side using a reverse proxy server for client access, and then by the rules will define the data packet to the real server.

The direction of the flow of traffic: Proxy -> real machine

Reverse proxy role:
(1) ensure the safety nets
(2) load balancing

nginx forward proxy, reverse proxy load balancing

Second, the forward proxy configuration (nginx proxy to do Internet)
environment: the same linux centos environment windows environment, nginx Download: http://nginx.org/en/download.html nginx / windows

1, the configuration Nginx
the shell> RPM -ivh https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm centos6
the shell> RPM -ivh https://mirrors.aliyun.com/epel/ Latest--Release-EPEL 7.noarch.rpm centos7
the shell> -Y yum mounting the install Nginx Nginx
the shell> Vim /etc/nginx/nginx.conf add two server, DNS add two

        ######################http代理####################
    server {
        listen 8088;
                 resolver 114.114.114.114;  #增加dns解析
        location / {
            proxy_pass http://$http_host$request_uri;
        }
    }
        ######################https代理###################
          server {
        listen 8089;
                 resolver 114.114.114.114;  #增加dns解析
        location / {
            proxy_pass https://$http_host$request_uri;
        }

shell>nginx -t 验证语法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

shell> systemctl restart nginx // centos7 restart the service
shell> service nginx restart // centos6 restart the service
shell> netstat -tunlp | grep 8088
tcp 0 0 0.0.0.0:8088 0.0.0.0: LISTEN 2441 / nginx
shell> netstat -tunlp | 8089 grep
TCP 0.0.0.0:8089 0 0 0.0.0.0:
the LISTEN 2441 / Nginx

2, configure your browser
to open IE-> Internet Options -> Connections -> LAN Settings -> Advanced -> set as shown below

nginx forward proxy, reverse proxy load balancing

3, the browser can access www.baidu.com

Third, the reverse proxy settings
Total Example: backend server group showed proxy requests, three servers, two of which run two instances of the same application, and the other as a backup server,
Nginx http load balancing will be applied to the distribution request :
HTTP {
upstream backend {
Server max_fails = XXXX weight = 2. 1. 5 = fail_timeout;
Server = XXXX. 1 max_fails weight = 2. 5 = fail_timeout;
Server XXXX Backup;
}
Server {
LOCATION / {
proxy_pass HTTP: // backend ; # loaded backend server
}
}
}

Guess you like

Origin blog.51cto.com/7603402/2422469