Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx jump with parameters

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Original link: https://www.baidu.com/benefit_detail?slug=bankofchina-20170320 destination link: https://www.test.cn/boc location ~ / benefit_detail {if ($args ~ * "slug=bankofchina-20170320") {rewrite ^ / benefit_detail / boc? Permanent;} try_files $uri $uri/ / index.php?$query_string;} Common jump cases: 1, jump www.myweb.com/connect to connect.myweb.comrewrite ^ / connect$ http://connect.myweb.com permanent;rewrite ^ / connect/ (. *) $http://connect.myweb.com/$1 permanent 2. Jump connect.myweb.com 301 to www.myweb.com/connect/ if ($host = "connect.myweb.com") {rewrite ^ / (. *) $http://www.myweb.com/connect/$1 permanent;} 3 to www.myweb.comif ($host! = 'www.myweb.com') {rewrite ^ / (. *) $http://www.myweb.com/$1 permanent } 4Jet www.myweb.com html$ html$ 123.html jumps to category/?cd=123rewrite "/ myweb.com (. *). Html$" / jump down to www.myweb.com/admin/index.php?s=if (!-e $request_filename) {rewrite ^ / admin/ (. *) $/ admin/index.php?s=/$1 last } 6, add / index.php?s=if (!-e $request_filename) {rewrite ^ / (. *) $/ index.php?s=/$1 last;} 7 to jump to 404rewrite ^ / xinwen/ ([0-9] +)\ .html$ / 404.html last link under xinwen such as 404rewrite ^ / (0-9] +) 8. Http://www.myweb.com/news/radaier.html 301 jumps to http://www.myweb.com/strategy/rewrite ^ / news/radaier.html http://www.myweb.com/strategy/ permanent;9, redirects the link to rewrite http://www.myweb.com/123/456.php / 404.html last;10, forbids htaccesslocation ~ / .ht {deny all } 11, you can disable requests such as .log.txt under multi-level directories under / data/; location ~ ^ / data {deny all;} 12, prohibit a single file location ~ / www/log/123.log {deny all } 13, http://www.myweb.com/news/activies/2014-08-26/123.html jumps to http://www.myweb.com/news/activies/123.htmlrewrite ^ / news/activies/2014\-([0-9] +)\-([0-9] +) / (. *) $http://www.myweb.com/news/activies/$3 permanent 14 admin/play Nginx Multi-conditional Redirect rewrite jumps to play if you need to open a link with play, but / admin/play cannot jump to if ($request_filename ~ (. *) / play) {set $payvar '1directed;} if ($request_filename ~ (. *) / admin) {set $payvar' 0requests;} if ($payvar ~'1') {rewrite ^ / http://play.myweb.com/ break } 15, http://www.myweb.com/?gid=6 jumps to http://www.myweb.com/123.html if ($request_uri ~ "/\? gid\ = 6") {return http://www.myweb.com/123.html; } regular expression matching, where: * ~ case-insensitive matching * * case-insensitive matching *! and! ~ * are case-sensitive mismatch and case-insensitive mismatch file and directory matching, respectively Among them: *-f and!-f are used to determine the existence of files *-d and!-d to determine the existence of directories *-e and!-e to determine the existence of files or directories *-x and!-x are used to determine whether files are executable. Flag tags are: * last is equivalent to the [L] tag in Apache. Indicates that the rewrite* break termination match is completed and the following rules are no longer matched * redirect returns 302 temporary redirect address column will display the redirected address * permanent returns 301 permanent redirect address column will display the meaning of each built-in variable of the redirected address nginx please refer to: https://blog.csdn.net/wanglei_storage/article/details/66004933 [understanding of nginx try_files] with try_files $uri $uri/ / index.php For example, when a user requests http://servers.blog.ustc.edu.cn/example, the $uri here is / example. Try_files will try to find this file on the hard drive. If there is a file named / $root/example (where $root is the directory where WordPress is installed), send the contents of the file directly to the user. Obviously, there is no file called example in the directory. Then look at $uri/, to add a /, that is, to see if there is a directory called / $root/example/. If it is not found, it will fall back to / index.php, the last option of try_files, and initiate an internal "sub-request", which is equivalent to nginx initiating a HTTP request to http://servers.blog.ustc.edu.cn/index.php. This request will be held by location~\. Php$ {...} catch, that is, into the FastCGI handler. And the specific URI and parameters are passed to FastCGI and WordPress programs in REQUEST_URI, so it is not affected by the changes in URI [$request_uri explanation] $request_uri is the complete url to cut out the first $host remaining part, such as http://www.baidu.com/pan/beta/test1?fid=3 this url, remove www.baidu.com the rest is it, the log will see that the printed $request_uri is actually / pan/beta/test1?fid=3. If you only visit www.baidu.com,$request_uri, there will be one in it. If ($request_uri ~ * "^ / $") means that there is only a domain name in the url, followed by nothing, such as www.baidu.com. If ($request_uri ~ * "test") means that the string after the domain name can be matched as long as it contains the keyword test, such as www.baidu.com/pan/beta/test3if ($request_uri ~ * "^ / $") {rewrite ^ http://kj.fnwtv.com/index.html permanent } if ($request_uri! ~ * "^ / $") {rewrite ^ http://www.fnwtv.com/ permanent;} [Nginx if condition judgment reference] the difference between adding and not adding / after https://www.cnblogs.com/saneri/p/6257188.htmllocation proxy_pass reference: https://blog.51cto.com/huangzp/1954575

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report