apisix icon indicating copy to clipboard operation
apisix copied to clipboard

help request: How to set the upstream host dynamically

Open KamenRiderKuuga opened this issue 1 year ago • 11 comments

Description

I'm trying to set the upstream host dynamically and unknown in advance like this:

remote_uri: /api/data-manage/... then set the host to: data-manage

I've tried the proxy-rewrite and the custom balancer, but still can't get this to work.

Is there any suggestion?

refer to: https://github.com/apache/apisix/discussions/9487#discussion-5199631

Environment

  • APISIX version: 3.1.0
  • Operating system: Linux gateway-5667d89f79-vl75g 5.4.164-1.el7.elrepo.x86_64 #1 SMP Mon Dec 6 12:28:33 EST 2021 x86_64 GNU/Linux
  • OpenResty / Nginx version: nginx version: openresty/1.21.4.1

KamenRiderKuuga avatar May 25 '23 06:05 KamenRiderKuuga

Can you show how to reproduce it?

ronething avatar May 25 '23 06:05 ronething

Can you show how to reproduce it?

It's not a bug report, I just want to do the above-mentioned function, need some help, thank you!

KamenRiderKuuga avatar May 25 '23 07:05 KamenRiderKuuga

Can you show how to reproduce it?

It's not a bug report, I just want to do the above-mentioned function, need some help, thank you!

Can you show an example config of route that you tried with which didn't work?

Revolyssup avatar May 26 '23 04:05 Revolyssup

try the traffic-split plugin @KamenRiderKuuga

qihaiyan avatar May 26 '23 07:05 qihaiyan

Can you show how to reproduce it?

It's not a bug report, I just want to do the above-mentioned function, need some help, thank you!

Can you show an example config of route that you tried with which didn't work?

No example configuration now.

I want to set the request regexp like this:

image

In this way, when requesting /api/data-manage/users, the http://data-manage/api/data-manage/users will be requested.

KamenRiderKuuga avatar May 26 '23 09:05 KamenRiderKuuga

try the traffic-split plugin @KamenRiderKuuga

Thanks, I'll try it.

KamenRiderKuuga avatar May 26 '23 09:05 KamenRiderKuuga

@qihaiyan I tried the traffic-split, it can't dynamically assign value to upstream_host according to the URI regexp.

KamenRiderKuuga avatar May 30 '23 16:05 KamenRiderKuuga

@qihaiyan I tried the traffic-split, it can't dynamically assign value to upstream_host according to the URI regexp.

Maybe you should develop your own plugin with reference to traffic-split.

qihaiyan avatar May 31 '23 01:05 qihaiyan

this is not supported.

shreemaan-abhishek avatar Mar 15 '24 14:03 shreemaan-abhishek

I have the same problem, and I write a custom plugin to achieve this.

checkout my gits: https://gist.github.com/br41n10/e2d378c7a04d4861b2f0cbf4d2476d71

This is a very basic implementation, modify on your needs.

br41n10 avatar Apr 12 '24 04:04 br41n10

i have the same problem,i write a customer plugin, but i don' known which is the best way? https://github.com/apache/apisix/issues/11342

xBoo avatar Jun 07 '24 10:06 xBoo