Two nginx server
nginx A: 192.168.1.48
nginx B: 192.168.1.56
A test method
Configure different rules nginx A then requests nginx A: http://192.168.1.48/foo/api
Observation nginx B receives the request, the specific operation is the view field $ request log
II. Testing process and results
Case 1
nginx A Configuration:
location /foo/ { proxy_pass http://192.168.1.56/; }
Received request nginx B: / api
Case 2
nginx A Configuration:
Received request nginx B: // api
Case 3
nginx A Configuration:
Received request nginx B: / foo / api
Case 4
nginx A Configuration:
location /foo/ { proxy_pass http://192.168.1.56; }
Received request nginx B: / foo / api
Case 5
nginx A Configuration:
Received request nginx B: / bar / api
Case 6
nginx A Configuration:
Received request nginx B: / bar // api
Case 7
nginx A Configuration:
Received request nginx B: / barapi
Case 8
nginx A Configuration:
Received request nginx B: / bar / api
See here is not the dizzy it, in fact there is a pattern
These cases are now arranged to form together, the results indicate that the request received nginx B
Table I
Case | location | proxy_pass | result |
---|---|---|---|
1 | /foo/ | http://192.168.1.48/ | /api |
2 | /foo | http://192.168.1.48/ | //api |
3 | /foo/ | http://192.168.1.48 | /foo/api |
4 | /foo | http://192.168.1.48 | /foo/api |
Table II
Case | location | proxy_pass | result |
---|---|---|---|
5 | /foo/ | http://192.168.1.48/bar/ | / Bar / fire |
6 | /foo | http://192.168.1.48/bar/ | / Bar // fire |
7 | /foo/ | http://192.168.1.48/bar | / Brpi |
8 | /foo | http://192.168.1.48/bar | / Bar / fire |
Three Parsing
Original request path: this article unified "/ foo / api"
location: location listed in the table above
proxy_pass: proxy_pass column in the table above
New request path: nginx original path after the processing request string
Proxy_pass focus on the analysis, can be divided into three forms
Then follow ip: port whether the access string as group 2, "/" is a string, and therefore classified as a class 1, 2 and 3 grouped together, these two categories will be described below
When the proxy_pass ip: port after the string was missed, nginx original request will be forwarded to the next path intact nginx, 3 and 4 as in the case
When the proxy_pass ip: port connected to the string when, Nginx location will be removed, then the remaining string concatenation proxy_pass generates a new request to the path from the original path of the request, the new request is then forwarded to the next path Nginx (upper case, and in fact this is the same, but excluding the empty string string ~)
For example, most people puzzled: Case 7. The proxy_pass ip: port after pick string "/ bar", so the location: "/ foo /" path from the original request: "/ foo / api" excluded, becomes "api", then "api" splicing to proxy_pass: http://192.168.1.48/bar epigenetic became the new request url: "http://192.168.1.48/barapi", therefore the next stop request is "/ barapi" nginx received.
Case 6: proxy_pass the ip: port after pick string "/ bar /", so the location: "/ foo" from an original request path "/ foo / api" excluded, becomes "/ api", then " / api "spliced to proxy_pass: http://192.168.1.48/bar/ epigenetic became the new request path:" http://192.168.1.48/bar//api ", therefore the next request is received by nginx / bar // api.
Other cases may be so, now finally I figured it out, no longer confused.
Reprinted https://www.jb51.net/article/146975.htm, only for their own learning