apisix icon indicating copy to clipboard operation
apisix copied to clipboard

I need to listen multiple ports and apply routing policies on specific port

Open Mr-Koala opened this issue 1 year ago • 4 comments

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 

Mr-Koala avatar Jan 30 '24 08:01 Mr-Koala

How are you running multiple instances ??

sheharyaar avatar Jan 30 '24 12:01 sheharyaar

@Mr-Koala this maybe helpful for your question https://github.com/apache/apisix/issues/10178

zll600 avatar Jan 30 '24 14:01 zll600

@Mr-Koala If this is fixed, please close the issue.

sheharyaar avatar Jan 30 '24 15:01 sheharyaar

  1. set config.yaml node_listen multiple ports:
node_listen:
      -    port: 8080
      -    port: 8081
      -    port: 8082
  1. 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
        }
    }
}'
  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
        }
    }
}'

hanqingwu avatar Jan 31 '24 08:01 hanqingwu

consider it resolved

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