Nginx Technology (4) Nginx address rewrite

Source: Internet
Author: User
Tags expression regular expression
server{
listen   ;
server_name  www.codesky.net;
location/{
proxy_pass   http://192.168.1.11:8080;
Proxy_redirect off  ;
Proxy_set_header  Host $host;
Proxy_set_header x-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Rewrite  "/zixun/([0-9]+) (/*). html$"  /zixun/$1/last;
Rewrite "/loanproduct/([0-9]+). html$"  /loanproduct/show?id=$1last;
}
}

Explain:

Rewrite "/zixun/([0-9]+) (/*). html$"/zixun/$1/last;

"/zixun/([0-9]+) (/*). html$" matches the URL address you entered for the regular expression, indicating/zixun/any number, at least once,/appears 0 or more times, already. HTML End

/zixun/$1/last; URLs that conform to the above rules are forwarded to/zixun/$1/to this link, which is the link you are implementing to get the data, and last is not matched for the following

For example: Http://www.xx.con/zixun/56.html will forward this request to the WWW.XX.CON/ZIXUN/56 servlet for data

The flags of the rewrite

Last-basically use this flag.
break-abort Rewirte, do not continue to match
Redirect-returns the temporarily redirected HTTP status 302
permanent-returns HTTP status for permanent redirection 301

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

Rules:

Generally in the location configuration rewrite, are used by the break, and the root of the location use last is better, because if the fastcgi or proxy access to the JSP file, the root location under the break is not access to

Pattern matching in the form of regular expressions, such as ~* and ~

~iscase-sensitivematch;

' ~ ' indicates a case sensitive match

~*specifiesacase-insensitivematch (Firefoxmatchesfirefox)

' ~* ' indicates a case-insensitive match (for example, "Firefox" Strings can successfully match "Firefox")

!~and!~*meantheopposite, "doesn ' tmatch"

The!~ and!~* represent the opposite of the regular matching rule, representing the following processing statements that cannot match the string execution of the current regular expression rule

Checkingfortheexistenceofafileusingthe-f and! f operators; Use the-f parameter and the!-f parameter to detect whether a file exists

Checkingexistenceofadirectoryusingthe-d and! -D operators using the-D parameter and the!-d parameter to detect if a directory (path) exists

Checkingexistenceofafile,directoryorsymboliclinkusingthe-e and! -e operators use-E and!-e to detect whether a file exists, a directory, or a symbolic link.

Checkingwhetherafileisexecutableusingthe-x and! -X Operators. Use-X and!-x to detect whether a file is executable

Partsoftheregularexpressionscanbeinparentheses,whosevaluecanthenlaterbeaccessedinthe to $ variables.

Part of the regular expression can be nested, and the part following the expression can be represented by a $ variable if the preceding expression is used.

This article from the "Live Well" blog, please be sure to keep this source http://wolfword.blog.51cto.com/4892126/1205216

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.