In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the use of Nginx regular expressions, the content is clear, interested friends can learn, I believe it will be helpful after reading.
Preface
Recently, I help customers configure the server, often modify the configuration file of Nginx, and frequently use formal matching rules. Here we sort out some commonly used regular parameters and rules for query.
The syntax rule location of Location in Nginx configuration [= | ~ | ~ * | ^ ~ |! ~ |! ~ *] / uri/ {… }
= exact match ~ case-sensitive regular match ~ * case-insensitive regular match ^ ~ indicates that URI begins with a regular string! ~ indicates case-sensitive regular mismatch! ~ * indicates case-insensitive regular mismatch / universal match, any request will match to
Matching order
In the case of multiple location configurations, the matching order is:
First match =
Second, match ^ ~
The second is regular matching according to the order in the file.
Finally, it is handed over to / universal matching.
When a match is successful, stop the match and process the request according to the current matching rule.
. Match any character except the newline character
\ w match letters or numbers or underscores or Chinese characters
\ s matches any blank character
\ d matching numbers
\ b match the beginning or end of a word
^ matches the beginning of the string
The end of the $matching string
* repeat zero or more times
+ repeat one or more times
? Repeat zero or once
{n} repeat n times
{n,} repeat n or more times
{n ~ m} repeat n to m times
*? Repeat any number of times, but repeat as little as possible
+? Repeat one or more times, but repeat as little as possible
?? Repeat 0 or 1 times, but repeat as little as possible
{n,m}? Repeat n to m times, but repeat as little as possible
{n,}? Repeat more than n times, but repeat as little as possible
\ W matches any character that is not letters, numbers, underscores, or Chinese characters
\ s matches any character that is not a blank character
\ d matches any non-numeric character
\ B matching is not the beginning or end of a word.
[^ x] matches any character except x
[^ aeiou] matches any character except the letters aeiou
Common rules
Exact matching
Location = / {proxy_pass http://127.0.0.1:9090/}
Forward all requests directly to port 9090 of the server.
Working with static files
# Directory match location ^ ~ / static/ {root/ webroot/static/;} # suffix matches location ~ *\. (gif | jpg | jpeg | png | css | js | ico) ${root/ webroot/res/;}
Forward dynamic requests to the back-end application server
# forward the request started by / account/ to the Account server location / account/ {proxy_pass http://127.0.0.1:8080/}# forward the request started by / order/ to the Order server location / order/ {proxy_pass http://127.0.0.1:9090/}
Rewrite instruction
Last is equivalent to the [L] tag in apache and stands for rewrite. Break after the matching of this rule is completed, the matching is terminated and the subsequent rules are no longer matched. Redirect returns 302 temporary redirection, and the browser address displays the URL address after the jump. Permanent returns 301 permanent redirection, and the browser address displays the URL address after the jump. URI rewriting is implemented using last and break, and the browser address bar remains unchanged. The alias instruction must be marked with last; when using the proxy_pass instruction, you need to use the break tag. After the implementation of this rewrite rule, the last mark will apply to the server {... The tag re-initiates the request, while the break tag terminates the match after the matching of this rule is completed. After reading the above, do you have a better understanding of the use of Nginx regular expressions? if you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.