Application of nginx in location on proxy_pass and rewrite

Label NginxRewriteLoationLocation
1431 people read comment(0) Collection Report

1, problem description


      Location * ^/OCC_DATACO_WEB/.*${

           Proxy_pass Http://datacollectbackend;

           Access_logMain logs/datacollection_access.log;

Now is that the OCC_DATACO_WEB name is too long, want to switch to DT, but the project is not on the line, you need to do a test, is to let OCC_DATACO_WEB to call the project inside.

That is before using access, and now changed to access. But the online project is still OCC_DATACO_WEB, but now the DT project has not been done, in the transition period to wait for the new DT perfect after removing the OCC_DATACO_WEB replaced by DT

Original blog address:Http://, without the original CSDN blogger mchdba allowed, may not be reproduced.

2, use proxy_pass location to do the jump

Jump directly to the DT and OCC_DATACO_WEB as the proxy_pass, as shown below

Location ^/dt/.*${*

Http: proxy_pass//datacollectbackend;

Logs/dt_error.log error error_log;
Logs/dt__access.log main access_log;

And then restart nginx, through the access, the results of the error is as follows:

Sorry, can not find the page

You usedURLMay be spelled incorrectly, the page may have been moved, or it may just be temporarily offline.
Re enter the correct URL, or return to the home page.

3, use rewrite to replace location

Location ^ */dt/.${
Rewrite /dt/ (. *) /OCC_DATACO_WEB/$1 Break;

Then restart nginx, the use of access, has entered into force, the success of the.

4, summary

Rewrite function is to use nginx to provide the global variables or their own set of variables, combined with regular expressions and flag bit to achieve URL rewriting and redirection. Rewrite can only be placed in the server{}, if{}, location{}, and can only be removed after the name of the domain name to pass the string outside the function, for exampleHttp:// Id=1&u=str?/a/we/index.php rewriting only. Grammar regex replacement [flag] rewrite;

If the relative domain name or parameter string functions, you can use a global variable match, or you can use the proxy_pass reverse proxy.
That watch rewrite and location function a bit like, can achieve the jump, the main difference lies in the rewrite is a path in the same domain name change access to resources, and the location is on a kind of path do access control or reverse proxy, proxy pass to other machines. In many cases, rewrite will be written in location, and the order in which they are executed is:

Execute rewrite block server instruction
Execute location match
Executes the rewrite instruction in the selected location
If one of the URI is rewritten, the loop executes 1-3 until it finds the actual file; the loop exceeds 500 times, and returns a 10 Server Error Internal error.

In this practice, it is necessary to DT project access point to the OCC_DATACO_WEB project, so it is necessary to only proxy_pass plus location is not enough, you need to rewrite.

step on
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit1000569 times
    • Integral:Sixteen thousand and fifty-nine
    • Grade
    • Rank:318th name
    • Original438
    • Reproduced:3
    • Translation:2
    • Comments:523
    My lessons
    Blog column
    Technology URL link
    Latest comments