NGINX重定向无需重写除IP和目录之外的URL

时间:2013-05-14 22:38:16

标签: configuration url-rewriting nginx

当我们将其删除以进行维护或更新时,我们会在网站上显示一个页面。基本伪代码逻辑看起来像这样:

if IP != 72.56.43.212 and location !~ /down then
   display down/

网址保持完整非常重要。例如,

Address Bar: http://www.example.com/abcd.html
Page Shown:  http://www.example.com/down

我还是NGINX配置的新手。任何帮助表示赞赏。

3 个答案:

答案 0 :(得分:0)

if ($remote_addr != "1.1.1.1") {
  rewrite . /down last;
}

答案 1 :(得分:0)

以前从来没有真正试过这个,但你可以使用nginx访问规则来做到这一点

error_page  403  http://example.com/down.html;
location / {
    allow 72.56.43.212;
    deny all;
}

答案 2 :(得分:0)

location /down {
   #empty block
}
location / {
    if ($remote_addr != 72.56.43.212) {
       rewrite ^ /down/index.php last;
    }
}