In terms of ordinary reverse proxies,
The configuration of the Nginx is 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 is going to be in trouble relative to Apache2.
For example, forward a request that starts with/wap/in the URL to a corresponding server in the background
You can set a variable in Nginx to temporarily save the path information after/wap/
Location ^~/wap/
{
if ($request _uri ~/wap/(\d+)/(. +))
{
set $bucketid $;
Set $params $
}
Proxy_pass http://mx$bucketid.test.com:6601/$params;
}
You can also first rewrite, and 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;
}
Pay attention to the last $args above, indicating that the last get parameter of the original URL is also given to the agent backstage
If you use a variable in proxy_pass (whether it is a host name variable or a trailing $ variable), you must add this code
However, if you do not use any variables after pass_proxy, you do not need to add, it will default to all the URLs to the agent to the background, such as:
Location ~*/wap/(\d+)/(. +)
{
proxy_pass http://mx.test.com:6601;
}
And Apache2 is a lot simpler:
Proxypassmatch ^/wap/(. *) $ http://192.168.132.147/$1
if ($host ~* www. *) {
set $host _without_www $;
Rewrite (. *) $ http://$host _without_www/www$1;
}
URL's/problem
when configuring Proxy_pass in Nginx, when the URL in the following Add/, equivalent to the absolute root path, then Nginx will not be the matching path in location part of the proxy walk, if not/, will be the matching path part of the agent to go.
The following four cases are accessed using http://192.168.1.4/proxy/test.html respectively.
First type:
location/proxy/{
proxy_pass http://127.0.0.1:81/;
}
will be represented to http://127.0.0.1:81/test.html this URL
Second I (relative to the first, the last one less/)
location/proxy/{
proxy_pass http://127.0.0.1:81;
}
will be represented 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 represented to http://127.0.0.1:81/ftlynx/test.html this URL.
The fourth case (relative to the third, last less one/):
location/proxy/{
proxy_pass http://127.0.0.1:81/ftlynx;
}
will be represented to http://127.0.0.1:81/ftlynxtest.html this URL
The results above are all I have tested with the log file. As can be seen from the result, it should be said that there are two kinds of situations to be correct. namely http://127.0.0.1:81 (the second of the above) this and http://127.0.0.1:81/.... (Above the first 1,3,4 species) this.