V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
daimaosix
V2EX  ›  NGINX

请问一下反向代理中 url 参数如何反代到 url 路径呢?

  •  
  •   daimaosix · 2021-10-19 21:53:51 +08:00 · 852 次点击
    这是一个创建于 891 天前的主题,其中的信息可能已经有所发展或是发生改变。

    源路径是:domain.b.com/sice/XXX

      location ^~ /icon/sice/ {
        proxy_redirect off;
        proxy_set_header Accept-Encoding '';
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://domain.b.com/sice/;
      }
    

    如何通过 domain.a.com/icon/sice/?id=123 传递给 domain.b.com/sice/123 呢?找了两天的资料了实在搞不定了。

    2 条回复    2021-11-03 10:10:18 +08:00
    q15158012160
        1
    q15158012160  
       2021-10-28 17:18:31 +08:00
    rewrite ^/icon/(.*)$ http://domain.b.com/$1/$arg_id break;
    Aluhao
        2
    Aluhao  
       2021-11-03 10:10:18 +08:00
    试试
    proxy_pass http://domain.b.com/sice/$request_uri;
    我的服务器是这么操作
    upstream IndiaApiServer {
    server 192.168.0.1:8888 weight=1;
    }
    proxy_pass http://IndiaApiServer$request_uri;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5314 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 07:14 · PVG 15:14 · LAX 00:14 · JFK 03:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.