feat: adds support for nginx variables in service_name param #12187
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added support for Nginx variables in the
service_name
parameter for service discovery. This allows dynamic service name resolution based on Nginx variables such as$host
,$http_host
, and others, working with all service discovery implementations (Consul, Eureka, Nacos, etc.).Detailed Description
Problem
The current implementation of service discovery in APISIX does not support using Nginx variables in the
service_name
parameter. This limits configuration flexibility as the service name must be hardcoded in the configuration, regardless of which service discovery implementation is used.Solution
Added support for Nginx variables in the
service_name
parameter at the upstream level. This change enables dynamic service name resolution across all service discovery implementations. For example:Usage Example
In this example, if a request comes to
service1.domain.local
, the$backend
variable will be set toservice1
, and APISIX will look for a service with this name in the configured service discovery system.Backward Compatibility
The change is fully backward compatible because:
service_name
Checklist