32

我正在尝试针对以下情况实施 nginx 重写规则

要求:

http://192.168.64.76/Shep.ElicenseWeb/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635 

应该重定向到:

http://localhost:82/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635 

我试过这个没有运气:

location /Shep.ElicenseWeb/ {
    rewrite ^/Shep.ElicenseWeb/ /$1 last;
    proxy_pass http://localhost:82;
}

为 nginx 执行这种重写的正确方法是什么?

4

2 回答 2

51

您的重写语句是错误的。

右边的 $1 指的是匹配部分中的一个组(用括号表示)。

尝试:

rewrite  ^/Shep.ElicenseWeb/(.*)  /$1 break;
于 2012-11-24T07:50:39.557 回答
8

您缺少尾部斜杠:

location /Shep.ElicenseWeb/ {
    proxy_pass http://localhost:82/;
}

这将在没有重写的情况下工作。

于 2018-07-22T23:05:37.193 回答