将阻止的IPredirect到nginx中的不同url

在我的Nginxconfiguration中

 location / { allow 198.168.0.1; deny all; } 

现在,我想redirect所有其他IP,除了允许的一个google.com ,我该怎么做?

我试过类似的东西

 location / { allow 198.168.0.1; deny all; rewrite ^ http://google.com/; } 

但是这直接redirect到所有IP的google.com 。 我只想要198.168.0.1访问页面,其他人将被redirect。

对此使用error_page指令。

 location / { allow 198.168.0.1; deny all; error_page 403 http://www.google.com/; } 

由于deny all将发生403错误,我们通过发送redirect到http://www.google.com/覆盖403处理。