nginx $document_uri 防止死循环

$document_uri 表示访问的url
现在我的需求是,访问 www.xxx.com 请求到 www.xxx.com/bbs/
在nginx配置文件中加入

if ($document_uri !~ ‘bbs’)
{
rewrite ^/(.*)$ http://www.xxx.com/bbs/$1 permanent;
}

而不是单独加一句 rewrite ^/(.*)$ http://www.xxx.com/bbs/$1 permanent;
如果只加rewrite 规则,而不限定条件,那么会造成死循环。 会访问到 http://www.xxx.com/bbs/bbs/bbs/bbs/…

原文地址:https://www.cnblogs.com/dantes91/p/5007943.html