In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Location matching rule 1. Instance server {location =\ {[configuration A]} location / {[configuration B]} location = / images/ {[configuration C]} location ^ ~ / static/ {[configuration D]} localtion ~ *\. (gif | jpg | png ) {[configure E]}} 2. Location syntax rules
Syntax:
Location = | ~ | ~ * | ^ ~ | @ / url/ {/ / Note =, ~, ~ *, ^ ~, @ are the matching rules of location. "|" indicates or. Omit other configurations}.
Rule description:
Symbolic meaning = literal exact matching, if matching, then jump out of the matching process (no longer regular matching) ~ start with case-sensitive regular matching ~ * start with case-insensitive regular matching ^ ~ the beginning means that uri starts with a regular string and is understood as matching url path / universal matching. When there is no regular expression match, any request will match to @ is not an ordinary location match. Variables for location internal redirection ~ case-sensitive regular matching at the beginning
Matching order of multiple location configurations:
First match: "=" second match: "^ ~" again match: file location writing order finally gives all requests to the wildcard ("/")
Note: after each match is successful, the match is stopped and the request will be processed according to the location of this match.
Follow the example above to illustrate the matching order:
First, compare the first location, if matching, stop the match, and process the request according to configuration A: location =\ {[configuration A]} then compare the second location, if matching, stop the match, and process the request according to configuration D: location ^ / static/ {[configuration D]} and then compare it in this order until a match is found. And process the request according to the matching configuration *
If none of the above matches, the general option is selected and the request is processed according to the matching configuration B:
Location / {[configuration B]} 3. Apply example precision rule (=) location = / {root / var/ww/html/;}
This rule indicates that only requests for access at the default address are matched, access address: http://NginxIP/
Match url path (^ ~) location ^ ~ / static/ {root / var/www/html/static;}
This rule indicates that only requests for access are matched with addresses starting with "/ static/". Access address: https://cache.yisu.com/upload/information/20200214/32/673.jpg | .gif | * .jpg "files, access address: https://cache.yisu.com/upload/information/20200214/32/674.jpg
Location ~ * / Test/ {root / var/www/html/;}
This rule indicates that there is an access request for Test in the matching url address. Case-insensitive test is also allowed. Access address: http://NginxIP/test/
Case sensitive (~) location ~ / Test/ {root / var/www/html/;}
This rule indicates that there is an access request for Test in the matching url address, which is case-sensitive. Test is matched. Access address: http://NginxIP/Test/
Default match (all rules can be matched) location / {root / var/www/html;}
This rule is the default match, and it can match all links accessed at the default address: http://NginxIP/login.html
Internal jump (@) location @ index_error {root / var/www/error/}
This rule indicates that it matches a request that starts with "/ index/". If the link status is 404, it will match this rule.
Detailed explanation of rewrite rules
The rewrite function of nginx is the same as that of apache. The main function of rewrite is to redirect RUL addresses. The rewrite function of Nginx is supported by PCRE software, and the rewrite module is the ngx_http_rewrite_module module. In a sense, it can be said that for the sake of beauty or friendly search caused by search, improve the ranking, etc.
1. Instance server {listen 80; server_name www.jkyst.xyz jkyst.xyz; if ($host! = 'www.jkyst.xyz') {rewrite ^ / (. *) $http://www.jkyst.xyz/$1 permanent;} location ~. *\. (png | gif | jpg) {return 403;}} 2.rewrite syntax rules
Syntax:
Rewrite regex replacement [flag]
Keywords rewritten by rewrite:rewrite cannot be omitted
Regex: this is a regular expression.
Replacement: here is the new content
Flag: here is the last flag tag
The flag tag says:
The flag tag indicates that last, that is, the (L) tag in apache, indicates that the completion of the rewrite,URL address will not change the break rule. After a successful match, the match will be stopped and the following rules will no longer be matched. The URL address will not change the redirect return 302 temporary redirection, the browser address will display the jumped URL address permanent returns 301 permanent redirection, the browser address bar will show the redirected URL address, and Nginx returns the response status code 301.
Description of related symbols:
The symbol description * represents the first 0 or more characters + represents the first 1 or more characters? Represents the first 0 or 1 character ^ represents the start position of the string $represents the end position of the string $n represents the nth parameter of the end of the string. A wildcard that represents any character 3. Application instance redirects multiple domain names to the same domain name server {listen 80; server_name www.jkyst.xyz jkyst.xyz abc.jkyst.xyz; if ($host! = 'www.jkyst.xyz') {rewrite ^ / (. *) $http://www,jkyst.xyz/$1 permanent;}}
When accessing "abc.jkyst.xyz", it automatically jumps to "www.jkyst.xyz". Here a "if" statement appears for judgment. If the result is true, the rewrite rewriting inside the statement will be performed.
Redirect to the specified file server {listen 80; server_name www.jkyst.xyz; if (!-e $request_filename) {rewrite ^ / test/ (. *) $http://www.jkyst.xyz/test1/$1 permanent;}} when the file does not exist
When the file or directory under the access "test" directory does not exist, jump to the file or directory under "test1". After the jump, the URL will be converted.
Server {listen 80; server_name www.jkyst.xyz; if (!-e $request_filename) {rewrite ^ / test/ (. *) $index.html last;}}
Indicates that when a file or directory under the access "test" directory does not exist, it will be redirected to the "index.html" file, and the URl will not convert it after the jump.
Server {listen 80; server_name www.jkyst.xyz; if (!-e $request_filename) {rewrite ^ / test/ ([0-9a-z] +) / ([0-9a-z] +) / (. *) $http://www.jkyst.xyz/test/$1$2$3 permanent;}
Directory switch, which means to convert the original directory to another directory, and [0-9a-z] indicates the directory name after conversion.
Access to files with the .sh suffix server {. Other configurations location. *\. (sh) ${return 405;}}
Indicates that a 405 error will be returned when accessing the file "* .sh"
Match user browser agent information server {listen 80; server_name www.jkyst.xyz; if ($http_user_agent ~ * ("Android") | (iPhone)) {rewrite ^ / test/ (. *) $http://www.jkyst.xyz/test/$1 permanent;}}
Means to redirect the files in the "test" directory when the browsing agents are Android and iPhone to change the access address
Prohibit htaccessserver {location ~ / .ht {deny all;}} 4. File directory matching parameter introduction-f determines whether the file exists return value true exists!-f determines whether the file exists return value false does not exist-d determines whether the directory exists return value true exists!-d determines whether the directory exists return value true does not exist-e determines whether the file or directory exists return value true exists!-e determines whether the file or directory exists Determine whether the file is executable if the return value true is nonexistent-x. The return value true is executable!-x determine whether the file is executable or not. The return value true is unexecutable.
Examples are as follows:
Server {listen 80; server_name www.jkyst.xyz; if (!-e $request_filename) {rewrite ^ / test/ (. *) $http://www.jkyst.xyz/test1/$1 permanent;}}
Determine whether a file or directory exists
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.