In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to configure the location function of Nginx". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1.Nginx location 1.1.location action
The function of the location instruction is to execute different applications according to the URI requested by the user.
1.2.location syntax
Location [= | ~ | ~ * | ^ ~] uri {.}
The above syntax is divided into four parts:
Location: directive [= | ~ | ~ * | ^ ~]: matching identity uri: matching website address {.}: configuration segment to be executed after matching uri
Note:
The difference between ~ and ~ * is: ~ case-sensitive, ~ * case-insensitive ^ ~: regular expressions are not checked after regular string matching
1.3.location matching example
Location = / {[configuration A]} location / {[configuration B]} location / documents {[configuration C]} location ^ ~ / images/ {[configuration D]} location ~ *\. (gif | jpg | jpeg) ${[configuration E]} the above configuration, when request "/", match configuration A request "/ index.html", match configuration B request "/ documents/docunment.html", match configuration C request "images/1.gif", match configuration D request "/ documents/1.jpg" Match configuration E
1.4.location configuration instance
Server {listen 80; server_name bbs.yygg.com; root html/bbs; location / {return 401;} location = / {return 402;} location / documents/ {return 403;} location ^ ~ / images/ {return 405 } location *\. (gif | jpg | jpeg) ${return 406;}
Test result
[root@nginx-01] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com402 [root @ nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com/ 402 [root @ nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com/index.html401 [root@ Nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com/documents/ documents. Html403 [root @ nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com/images/1.gif405 [root@nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com / documents/ 1.jpg406 [root @ nginx-01 ~] # curl-s-o / dev/null-I-w "% {http_code}\ n" bbs.yygg.com/yyang/401
The returned status code also matches the rules in the configuration.
1.5. The sequence description of matching without uri and special character combinations
Location = / {}: exact matching location ^ ~ / images/ {}: regular string matching, no regular matching location ~ *\. (gif | jpg | jpeg) ${}: regular matching location / documents/ {}: regular string matching, if there is regular matching, priority matching regular location / {}: after all location mismatches, the default matching "how to configure the location function of Nginx" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.