I used nginx as the reverse proxy to proxy Baidu (www.baidu.com) and modified the host file locally during the test. Resolve www.baidu.com to the nginx Proxy Server (74.91.23.207 ).
# Vim/etc/hosts
Next let's take a look at the nginx configuration file segment (where: Server 115.239.210.27 is Baidu's server address)
Next, enter www.baidu.com in the browser and send an HTTP request. Ping it to see that it is a request sent to 74.91.23.207.
So how does nginx handle the request after it reaches 74.91.23.207?
Take a look at the wireshark packet (fliter: IP. src = 192.168.100.11 & HTTP. Host = "www.baidu.com" & HTTP. Request. Method = "get ")
Based on the above get package data explanation:
1. When an HTTP request is sent to nginx for processing, nginx will first retrieve the host (www.baidu.com) in the header, and thenAll configuration filesTo determine which server block to process the request. (Of course, sometimes a host may match SERVER_NAME in multiple server blocks. In this case, the server block actually processed will be selected based on the matching priority. The priority will not be detailed here .)
2. at this point, we can see that the HTTP request matches SERVER_NAME, so that nginx will match the location according to the request URI field in the header, as shown in the preceding configuration file. Location/is matched /.
3. Next, we can see the proxy _ pass http: // rocdn through nginx. This is reverse proxy processing. In this example, we use the nginx upstream module for reverse proxy implementation.
4. You can find the corresponding upstream block through the rocdn in the proxy _ pass http: // rocdn;, and then perform another proxy request based on the server 115.239.210.27: 80,
The content of the get packet sent: The Host field and request URI field are the same as those above,
5. after the current HTTP request arrives at Baidu's server 115.239.210.27, if Baidu is also nginx, the server will perform SERVER_NAME and location matching like the above nginx handles HTTP requests, return the requested resource to the proxy server.
6. The nginx reverse proxy server receives the resources returned by the Baidu server and then returns them to the client browser.
The above is the general process of HTTP request and processing when nginx acts as the response proxy.