|
1. Description of the problem
upstream datacollectbackend {
#ip_hash;
server 10.234.1.211:6100 max_fails = 5 fail_timeout = 30s;
server 10.234.1.26:7100 max_fails = 5 fail_timeout = 30s;
}
location ~ * ^ / OCC_DATACO_WEB /.*$ {
include deny.conf;
proxy_pass http: // datacollectbackend;
include proxy.conf;
error_log logs / datacollection_error.log error;
access_log logs / datacollection_access.log main;
}
Now just think OCC_DATACO_WEB name is too long, and would like to replace dt, but the project has not been on the line, you need to be a test, it is to let www.linuxidc / dt / possystem to call OCC_DATACO_WEB project to go inside.
That previously www.linuxidc / OCC_DATACO_WEB / possystem access, now replaced www.linuxidc / dt / possystem access. But the project still OCC_DATACO_WEB online, but now the project has not yet finished dt, in a transition period to wait for a new dt perfect after removing OCC_DATACO_WEB replaced dt
2, with the location of proxy_pass do Jump
And jump directly to OCC_DATACO_WEB same proxy_pass dt follows
location ~ * ^ / dt /.*$ {
include deny.conf;
proxy_pass http: // datacollectbackend;
include proxy.conf;
error_log logs / dt_error.log error;
access_log logs / dt__access.log main;
}
Then restart nginx, by www.linuxidc / dt / possystem visit, the results being given as follows:
Sorry, can not find that page
URL you are using the likely misspelled, this page may have moved, or it may just be a temporary offline.
Retype the correct URL, or Home
3, instead of using the rewrite location
location ~ * ^ / dt /.*$ {
rewrite /dt/(.*) / OCC_DATACO_WEB / $ 1 break;
}
Then restart nginx, use www.linuxidc / dt / possystem access, already in effect, a success.
4, summary
rewrite function is to use global variables nginx provided or set up their own variables, combined with regular expressions and flags achieve url rewrite and redirect. rewrite only on the server {}, location {}, if {}, and only on the parameters passed to remove the domain name back to work outside of the string, for example http://linuxidc.com/a/we/index .php? id = 1 & u = str only /a/we/index.php rewritten. Syntax rewrite regex replacement [flag];
If the relative domain name or function parameter string, you can use global variables to match, or you can use a reverse proxy proxy_pass.
Look rewrite capabilities and location show a bit like, can realize the jump, the main difference is that the rewrite is to change the access to resources within the same domain path, but location is a class path to make access control or reverse proxy, to other machines can proxy_pass . In many cases it will be written in the rewrite location where their execution order is:
Rewrite instruction execution server block
Execution location Match
Implementation of the selected location in the rewrite instruction
If either step URI is rewritten, re-execute cycle 1-3, until you find the file's existence; circulation of more than 10 times, 500 Internal Server Error error is returned.
This practice is the need to project a point to visit dt OCC_DATACO_WEB project to go inside, so you need only add proxy_pass location is not enough, we need to rewrite the. |
|
|
|