除非url参数存在,否则Nginx否认503的URL

我目前限制一个WordPress文件wp-login.php只有我的IP地址 – 但我想允许访问该页面,如果给定的URL参数存在。

所以基本上这是我所尝试的

location ~ ^/(wp-admin|wp-login\.php) { if ($arg_action = "true") { break; } allow xx.xxx.xxx.xxx; deny all; // fastcgi_params } 

所以在这个代码片段中,如果用户访问wp-login.php?action = true,页面应该显示。 但是,如果用户访问wp-login.php,他们应该被拒绝。

这个代码不起作用,任何提示将不胜感激。

这应该会为你工作,检查arg如果发现它返回error 418 ,然后将其交给指定的位置iplocation然后检查ips,并执行其余的configuration

 error_page 418 = @iplocation; recursive_error_pages on; location ~ ^/(wp-admin|wp-login\.php) { if ($arg_action = "true") { return 418; } location @iplocation { allow xx.xxx.xxx.xxx; deny all; // fastcgi_params } 

问题是,如果{}, 中断就会退出。 它不会退出位置。

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#break

该代码应该工作:

 location ~ ^/(wp-admin|wp-login\.php) { if ($arg_action != "true") { return 403; } allow xx.xxx.xxx.xxx; deny all; // fastcgi_params } 

编辑:固定错字。