The reverse proxy proxy_pass configuration method of "Go" nginx server is explained
Transferred from: http://www.jb51.net/article/78746.htm
In terms of normal reverse proxies,
Nginx configuration is still relatively simple, such as:
Location ~/* {Proxy_pass http://127.0.0.1:8008;}
Or you can
Location/{proxy_pass http://127.0.0.1:8008;}
The configuration of the reverse proxy for Apache2 is:
proxypass/ysz/http://localhost:8080/
However, if you want to configure a relatively complex reverse proxy
Nginx relative Apache2 is going to be a bit troublesome.
For example, a request that starts with/wap/in a URL is forwarded to a server that corresponds to the background
You can set a variable in the Nginx to temporarily save the path information behind the/wap/.
Location ^~/wap/{if ($request _uri ~/wap/(\d+)/(. +)) {Set $bucketid $1;set $params $;} Proxy_pass http://mx$bucketid.test.com:6601/$params;}
You can also rewrite first, then agent:
Location ^~/wap/{rewrite/wap/(\d+)/(. +)/$2? $args break;proxy_pass http://mx$1.test.com:6601;}
Or
Location ~*/wap/(\d+)/(. +) {Proxy_pass http://mx$1.test.com:6601/$2? $args;}
Notice the last of the above? $args, indicating that the last get parameter of the original URL is also proxied to the background
If a variable is used in Proxy_pass (whether it is a hostname variable or a trailing $ variable), this code must be added
However, if you do not use any variables after pass_proxy, you do not need to add, it will default to all the URLs are proxied to the background, such as:
Location ~*/wap/(\d+)/(. +) {Proxy_pass http://mx.test.com:6601;}
And the Apache2 is relatively simple:
Proxypassmatch ^/wap/(. *) $ http://192.168.132.147/$1 if ($host ~* www. *) { set $host _without_www $; Rewrite (. *) $/HTTP $host _without_www/www$1; }
URL/problem
When configuring Proxy_pass in Nginx, when the following URL is added/, the equivalent is the absolute root path, the Nginx will not be the location of the matching path part of the proxy walk, if not/, will be the matching path part also to the agent go.
The following four cases are accessed separately using http://192.168.1.4/proxy/test.html.
The first type:
location/proxy/{ proxy_pass http://127.0.0.1:81/;}
will be proxied to http://127.0.0.1:81/test.html this URL
The second (relative to the first, the last one less/)
location/proxy/{ proxy_pass http://127.0.0.1:81;}
will be proxied to http://127.0.0.1:81/proxy/test.html this URL
The third type:
location/proxy/{ proxy_pass http://127.0.0.1:81/ftlynx/;}
will be proxied to http://127.0.0.1:81/ftlynx/test.html this URL.
The fourth case (in relation to the third, the last Less/):
location/proxy/{ proxy_pass http://127.0.0.1:81/ftlynx;}
will be proxied to http://127.0.0.1:81/ftlynxtest.html this URL
The above results are all I have tested with the log file. As can be seen from the results, it should be said to be divided into two cases correctly. That is http://127.0.0.1:81 (the second of the above) this and http://127.0.0.1:81/.... (1,3,4 above) this kind of.
The reverse proxy proxy_pass configuration method of "Go" nginx server is explained