current position:Home>What we learned today - nginx Rewrite Module

What we learned today - nginx Rewrite Module

2021-08-25 00:32:39 Ten days to the South

Rewrite modular

One , Definition :

Rewrite The main implementation url Address rewrite , as well as url Address jump . That is, the user requests web Server's URL Change the address to another URL Address process .

Two ,Rewrite Rewrite Module

1.if Condition determination instruction ;

Matching rules

~ ~* !~ =
Fuzzy matching Case-insensitive matching Mismatch Exactly match

2. grammar

if ($request_uri ~* ‘id=1234’) {}
If requested by the user uri matching 1234 Then meet the conditions ;
if ( $http_user_agent ~* “chrome|firefox”) {}
If the user's browser is chrome and firefox Then meet the conditions ;
if ( $http_accept_language ~* “zh-CN|zh”) {}
If the language of the browser for users is Chinese , Then meet the conditions ;

2.set Set variable command ;

set $variable value;
Set variable value .

3.return Return data instruction ;

return code " ";
Return status code + describe ;
return code http://;
return URL, Perform site jump ;

4. rewrite flag;

rewrite a b;
from a Jump to b;

5.break and last;

stay location{} Inside , encounter break, Ben
location{} Everything inside and behind location{} All instructions in are no longer executed .
stay location{} Inside , encounter last, Ben
location{} Internal subsequent instructions are no longer executed ,
And the rewritten url Will be right where server{…} Tag relaunch request , Match the rules from beginning to end , Which match is executed .

6.redirect and permanent;

redirect A temporary jump 302
permanent Jump forever 301

copyright notice
author[Ten days to the South],Please bring the original link to reprint, thank you.

Random recommended