Nginx configuration is relatively simple, such as:

Location ~ /* {proxy_pass http://127.0.0.1:8008; }Copy the code

Or you can

Location / {proxy_pass http://127.0.0.1:8008; }Copy the code

The Apache2 reverse proxy configuration is:

ProxyPass /ysz/ http://localhost:8080/
Copy the code

However, it is more difficult to configure a complex reverse proxy such as Nginx to forward a request starting with /wap/ to a server in the background. You can set a variable in Nginx to temporarily store the path information after /wap/

location ^~ /wap/
{
    if ($request_uri ~ /wap/(\d+)/(.+))
    {
        set $bucketid $1;
        set $params $2;
    }
    proxy_pass http://mx$bucketid.test.com:6601/$params;
}
Copy the code

Rewrite first and then proxy:

location ^~ /wap/{ rewrite /wap/(\d+)/(.+) /$2? $args break; proxy_pass http://mx$1.test.com:6601; }Copy the code

or

location ~* /wap/(\d+)/(.+)
{
    proxy_pass http://mx$1.test.com:6601/$2?$args;
}
Copy the code

Notice the last one up here, right? If proxypass is used in proxypass, the last get parameter of the original URL is also given to the proxy. If proxypass is used in proxypass, the last GET parameter of the original URL is given to the proxy. If you use variables in proxypass (either the hostname variable 1 or the $2 variable after it), then you must add this code. If pass_proxy does not use any variables, then you do not need to add this code. By default, it gives all urls to the proxy in the background, as in:

location ~* /wap/(\d+)/(.+)
{
    proxy_pass http://mx.test.com:6601;
}
Copy the code

Apache2 is much simpler:

ProxyPassMatch ^ / wap/(. *) $http://192.168.132.147/$1 if ($host WWW. ~ * (. *)) {set $host_without_www $1; rewrite (.*)$ http://$host_without_www/www$1; }Copy the code

Nginx does not partially proxy the path that matches the url in the proxy_pass file. If there is no /, the matching portion of the path is also given to the agent.

The following four cases with http://192.168.1.4/proxy/test.html for a visit. The first:

Location /proxy/ {proxy_pass http://127.0.0.1:81/; }Copy the code

Is the agent to the url http://127.0.0.1:81/test.html

The second one (relative to the first one, the last one less /)

Location /proxy/ {proxy_pass http://127.0.0.1:81; }Copy the code

Is the agent to the url http://127.0.0.1:81/proxy/test.html

The third:

The location/proxy / {proxy_pass http://127.0.0.1:81/ftlynx/; }Copy the code

Is the agent to the url http://127.0.0.1:81/ftlynx/test.html.

The fourth case (relative to the third, the last one less /) :

The location/proxy / {proxy_pass http://127.0.0.1:81/ftlynx; }Copy the code

Is the agent to the url http://127.0.0.1:81/ftlynxtest.html

The above results are all tested by myself with log files. As can be seen from the results, it is correct to say that there are two cases. The http://127.0.0.1:81 (the second) the and http://127.0.0.1:81/… (Number 1, 3 and 4 above) This kind.