如何在nginx

时间:2017-08-09 03:24:06

标签: regex nginx url-rewriting location

我试图将流量重定向到我们的新服务器,但旧服务器(Mac OS)使用不区分大小写的文件名,而新的(嵌入式)使用Linux(区分大小写)。 我的问题是重定向来自:

的流量
http://server.com/NEW/variable_url

http://server.com/new/variable_url

(注意较低的' new')。

我希望能够在不使用perl或lua或其他模块的情况下为nginx执行此操作,因为此服务器在嵌入式环境中运行。

到目前为止,我试过了:

 location ~* ^/new/ {
       access_log /var/log/nginx/new.log combined;
        rewrite ^/new/(.*)$ $1 permanent;
     }

没有成功。

3 个答案:

答案 0 :(得分:0)

也许是这样的?

location / NEW {

重写^ / NEW /(.*)$ / new;

}

答案 1 :(得分:0)

如果您想重定向特定链接/NEW/exampe1的流量,可以尝试

location =/NEW/example1
{
rewrite ^ /new/example1 last;
}

答案 2 :(得分:0)

自己解决了。我错过了指向Web服务器根目录的root指令。所以对于任何有兴趣的人来说,解决方案是:

location ~* ^/NEW/ {
        root /etc/nginx/html/;
        rewrite /NEW/(.*)$ /new/$1 permanent;
     }