【问题标题】:Nginx rewrite rule with proxy pass使用代理通行证的 Nginx 重写规则
【发布时间】:2012-11-12 10:02:42
【问题描述】:

我正在尝试针对以下情况实现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 执行这种重写的正确方法是什么?

【问题讨论】:

    标签: url-rewriting nginx


    【解决方案1】:

    你的重写语句是错误的。

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

    试试:

    rewrite  ^/Shep.ElicenseWeb/(.*)  /$1 break;
    

    【讨论】:

    • 你可以试试:> location / { rewrite ^/(.*) /Shep.ElicenseWeb/$1 break; proxy_pass 127.0.0.1:82; }
    【解决方案2】:

    您缺少尾部斜杠:

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

    这无需重写即可工作。

    【讨论】:

      猜你喜欢
      • 2019-11-02
      • 2015-02-14
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      相关资源
      最近更新 更多