apisix
apisix copied to clipboard
I need to listen multiple ports and apply routing policies on specific port
Description
As a user, I have started multiple listening ports in APISIX, and I need to apply the defined routing policies on specific ports. However, I couldn't find any relevant documentation in the official documentation. The answer provided by GPT is as follows, but it doesn't seem to work:
apisix:
node_listen:
- host: "0.0.0.0"
port: 8080
proto: http
routes:
- name: route1
methods: ["GET", "POST"]
uris: ["/api"]
hosts: ["example.com"]
upstream:
type: roundrobin
nodes:
- target: "http://127.0.0.1:8000"
attributes:
node_listen:
- port: 8080
How are you running multiple instances ??
@Mr-Koala this maybe helpful for your question https://github.com/apache/apisix/issues/10178
@Mr-Koala If this is fixed, please close the issue.
- set config.yaml node_listen multiple ports:
node_listen:
- port: 8080
- port: 8081
- port: 8082
- set route vars match port 8081
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/port1",
"vars": [
["server_port", "==", "8081"]
],
"upstream": {
"type": "roundrobin",
"nodes": {
"www.port1.com": 1
}
}
}'
- set route vars match port 8082
curl http://127.0.0.1:9180/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/port2",
"vars": [
["server_port", "==", "8082"]
],
"upstream": {
"type": "roundrobin",
"nodes": {
"www.port2.com: 1
}
}
}'
consider it resolved