加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

NGINX Proxy_Pass删除url substring

发布时间:2020-12-13 21:12:44 所属栏目:Nginx 来源:网络整理
导读:我有一个NGINX充当反向代理.我需要从URL中删除子串string_1,其余的URL是可变的. 例: Origin: http://host:port/string_1/string_X/command?xxxxxDestination: http://internal_host:port/string_X/command?xxxxx nginx.conf: location /string_1/ { proxy_

我有一个NGINX充当反向代理.我需要从URL中删除子串string_1,其余的URL是可变的.

例:

Origin: http://host:port/string_1/string_X/command?xxxxx

Destination: http://internal_host:port/string_X/command?xxxxx

nginx.conf:

location /string_1/   { 

    proxy_pass  http://internal_host:port/$request_uri$query_string;

谢谢,

@pcamacho

最佳答案
我找到了重写proxy_pass URL的方法:

  location  /string_1/   {  

    if ($request_uri ~* "/string_1/(.*)") { 
            proxy_pass  http://internal_host:port/$1;
    }   

  }

问候,

@pcamacho

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读