Regular Expression Matching of nginx forwarding rules, where :*~ Case-sensitive matching *~ * Case-insensitive matching *!~ And !~ * These are case-insensitive and case-insensitive files and directories. *-f and! -F is used to determine whether a file exists *-d and! -D... regular expression matching of nginx forwarding rules, where :*~ Case-sensitive matching *~ * Case-insensitive matching *!~ And !~ * These are case-insensitive and case-insensitive files and directories. *-f and! -F is used to determine whether a file exists *-d and! -D is used to determine whether a directory *-e and! -E is used to determine whether a file or directory exists *-x and! -X is used to determine whether a file can run the flag: * last is equivalent to the [L] Mark in Apache, indicating that rewrite * break is completed to terminate the match, no longer match the following rule * redirect returns 302 the address bar of the temporary redirection will display the address after the jump * permanent returns 301 permanent redirection address bar will display the address after the jump some available global variables are, conditional judgment can be used (to be supplemented) $ args $ content_length $ content_type $ document_root $ document_uri $ host $ response $ http_cookie $ limit_rate $ response $ request_method $ response $ remote_port $ remote_user $ response $ request_uri $ query_string $ scheme $ server _ Protocol $ server_addr $ server_name $ server_port $ uri combined with the QeePHP example if (! -D $ request_filename) {rewrite ^/([a-z-A-Z] +)/([a-z-A-Z] + )/? (. *) $/Index. php? Namespace = user & controller = $1 & action = $2 & $3 last; rewrite ^/([a-z-A-Z] + )/? $/Index. php? Namespace = user & controller = $1 last; break; convert multiple directories to the parameter abc.domian.com/sort/2 => abc.domian.com/index.php? Act = sort & name = abc & id = 2if ($ host ~ * (. *)/. Domain/. com) {set $ sub_name $1; rewrite ^/sort // (/d + )//? $/Index. php? Act = sort & cid = $ sub_name & id = $1 last;} directory swap/123456/xxxx->/xxxx? Id = 123456 rewrite ^/(/d +)/(. +) // $2? Id = $1 last; for example, set nginx to redirect to the/nginx-ie directory when you use ie: if ($ http_user_agent ~ MSIE) {rewrite ^ (. *) $/nginx-ie/$1 break;} automatically adds "/" if (-d $ request_filename) {rewrite ^ /(. *) ([^/]) $ http: // $ host/$1 $2/permanent;} disable htaccesslocation ~ //. Ht {deny all;} multiple directories are prohibited from location ~ ^/(Cron | templates)/{deny all; break;} prohibit requests for files starting with/data from/data/directory levels such as .log.txt. location ~ ^/Data {deny all; the specified directory cannot be banned. log.txt can request location/searchword/cron/{deny all;} to disable the location of a single file ~ /Data/SQL/data. SQL {deny all; specify the expiration time for favicon.icoand robots.txt. in this case, if favicon.icois set to 99 days, and Robots.txt is set to 7 days, the location of the 404 error log is not recorded ~ (Favicon. ico) {log_not_found off; expires 99d; break;} location ~ (Robots.txt) {log_not_found off; expires 7d; break;} sets the expiration time of a file, which is 600 seconds, and does not record the access log location ^ ~ /Html/scripts/loadhead_1.js {access_log off; root/opt/lampp/htdocs/web; expires 600; break ;} file anti-leeching and set the Expiration Time. here, return 412 is the custom http status code. the default value is 403, so that you can find the correct request for leeching "rewrite ^/ http://leech.c1gstudio.com/leech.gif ; "Show an anti-Leech image" access_log off; "does not record access logs, reducing pressure" expires 3d "all Files 3 days of browser cache location ~ * ^. + /. (Jpg | jpeg | gif | png | swf | rar | zip | css | js) $ {valid_referers none blocked * .c1gstudio.com * .c1gstudio.net localhost success; if ($ invalid_referer) {rewrite ^/ http://leech.c1gstudio.com/leech.gif ; Return 412; break;} access_log off; root/opt/lampp/htdocs/web; expires 3d; break;} only a fixed ip address is required to access the website, add the password root/opt/htdocs/www; allow 208.97.167.194; allow 222.33.1.2; allow 231.152.49.4; deny all; auth_basic "C1G_ADMIN"; auth_basic_user_file htpasswd; convert files under multi-level directories into a file, enhance seo effect/job-123-456-789.html point to/job/123/456/789.html rewrite ^/job-([0-9] +) -([0-9] +)-([0-9] + )/. html $/job/$1/$2/jobshow_assist3.html last; point a folder under the root directory Level 2 directories such as/shanghaijob/point to/area/shanghai/If you change last to permanent, the browser address bar displays/location/shanghai/rewrite ^/([0-9a-z] +) job /(. *) $/area/$1/$2 last; the problem in the above example is that the rewrite ^/([0-9a-z] +) will not match when accessing/shanghai) job $/area/$1/last; rewrite ^/([0-9a-z] +) job /(. *) $/area/$1/$2 last; in this way,/shanghai can also be accessed, but the relative link on the page cannot be used, such. the actual address of/list_1.html is/area/shanghia/list_1.html, which is converted to/list_1.html and cannot be accessed. Then I cannot add automatic redirect (-d $ request_filename). It has a condition that it must be a real Directory, while my rewrite is not, so there is no effect if (-d $ request_filename) {rewrite ^ /(. *) ([^/]) $ http: // $ host/$1 $2/permanent;} it's easy to understand the cause, let me jump to rewrite ^/([0-9a-z] +) job $/$ 1job/permanent; rewrite ^/([0-9a-z] +) job /(. *) $/area/$1/$2 last; redirection when the file and directory do not exist: if (! -E $ request_filename) {proxy_pass http://127.0.0.1 ;}
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