在nginx(旁路)IP中重写规则

时间:2012-10-10 14:07:26

标签: nginx rewrite

我有一个重写规则如下:

if ( $request_uri ~ https://subdomain.domain.com/abc/xyzdirector/login.do ) {
return    444;
}

现在这个工作正常,但是,我想要对此规则有例外。我想允许IP A.B.C.D通过,即此IP不应受此规则约束。如何做到这一点?

1 个答案:

答案 0 :(得分:3)

http://wiki.nginx.org/HttpCoreModule#Variables包含以下内容:

$remote_addr
The address of the client. 

$binary_remote_addr
The address of the client in binary form; 

注:

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if表示if语句允许的上下文为服务器和位置

换句话说,你不能嵌套if语句,所以你会得到如下内容:

location /abc/xyzdirector/login.do { 
  if ( $remote_addr != <allowed adress> ) { return 444;}       
  #if you get here it was an allowed adress so add config to server the request.
}