The concept of forward proxy and reverse proxy

Forward proxy: Machines in the LAN access web sites outside the LAN with proxy services. The object of the proxy is the client, the goal is to access the resources of the external network. (eg: Go over the wall to see the outside world by proxy)

Reverse proxy: The LAN provides resources to the Internet and allows other Internet users to access resources on the LAN through a proxy server. The object of the proxy is the server, the goal is to allow other clients to access the resources of the server (eg: load balancing, static resource server within the company)

Conclusion: Forward proxy and reverse proxy involve the same technology, mainly because of different application scenarios.

Two, forward proxy configuration instructions

1. Resolver command: used to specify the IP address of the DNS server

2. The resolver_timeout command is used to set the timeout period for DNS domain name resolution

3. Proxy_pass directive: used to set the protocol and address of the proxy server.

Because forward proxy services are rare, there are fewer instructions and simpler functions

(In addition, regarding whether nginx forward proxy supports HTTPS, it has not been tried for the moment, and will be added in the future practice.)

Reverse proxy configuration instructions

1. Proxy_pass directive: used to set the address of the proxy server

Syntax: proxy_pass URL; The URL contains elements such as transport protocol, host name, IP address and port number. The transport protocol is usually"http"or"https"(1) "proxy_list" indicates upstream proxy_list {server http://192.168.4.30/uri/; The server http://192.168.12.19/uri/; } server { location / { proxy_pass proxy_list; Upstream proxy_list {server 192.168.4.30/uri/; Server 192.168.12.19 / uri /; } server { location / { proxy_pass http://proxy_list; }} Also need to pay attention to whether the URL contains a URI to access"http://www.test.com/test/index.html"Server {server_name www.test.com; location /test/
    {
        # proxy_pass http://192.168.12.19; -- - > go to "http://192.168.12.19/test/index.html"
        # proxy_pass http://192.168.12.19/index/; -- - > go to "http://192.168.12.19/index/index.html"
        # proxy_pass http://192.168.12.19/; -- - > go to "http://192.168.12.19/index.html"}}Copy the code

2. Proxy_hide_header directive: Set to hide some header fields when sending HTTP responses

3. Proxy_pass_header directive: Sets some header field information to be sent

4. Proxy_pass_request_body and proxy_PASS_request_HEADERS: specifies whether to send the request body and headers from the client to the proxy server

5. Proxy_set_header and proxy_set_body directives: set the new request header and body to be sent to the proxy server

There are 14 instructions, and then slowly fill, first of their own common instructions sorted out first.

Nginx server load balancing configuration

The nginx server is now a statically prioritized weighted polling algorithm that uses the configuration of proxy_pass and upstream directives, as shown in the following example

Upstream Backend {server 192.168.4.30 weight=5; Server 192.168.12.19 weight = 3; Server 192.168.11.17;# the default weight = 1
}
server
{
    location /
    {
        proxy_pass http://backend;
        proxy_set_header Host $host; }}Copy the code

Weighted polling is implemented based on the priorities of backend server groups. 192.168.4.30 has the highest priority for receiving and processing requests. 192.168.11.17 has the lowest priority for processing requests. 192.168.12.19 has the medium priority.

Polling load balancing is to set the weight of all server groups to be the same

Five, the summary

Nginx proxy is often involved in my work, but I always have a little knowledge or use with baidu…… I hope you can have the same idea as me through this article can have a clearer understanding of nginx agent and application ability.

In addition, the study time is hasty, welcome criticism and correction!