Search code examples
kongkonga

Expose Kong API gateway at custom domain/URL


I have setup Kong API gateway following the documentation here. With the curl command below, I can confirm that Kong is up and responding via localhost.

curl -i http://localhost:8001/services
    
    HTTP/1.1 200 OK
    Date: Thu, 13 May 2021 15:39:32 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Access-Control-Allow-Origin: http://localhost:8002
    X-Kong-Admin-Request-ID: xeUkwshQPRXA5T9bPQmxsmPcspJCGU2L
    vary: Origin
    Access-Control-Allow-Credentials: true
    Content-Length: 23
    X-Kong-Admin-Latency: 5
    Server: kong/2.3.3.2-enterprise-edition

My question is, for production, how to configure Kong to respond to DNS/URL?

I have set up a DNS record on AWS Route 53 to point traffic at the IP of this server where Kong is deployed. With a standalone application - a Node/Express app for exmaple, I would set up a reverse proxy ie NGINX to route requests received to the server from a URL onwards to the app. However, as Kong is the API gateway, that wouldn't be appropriate.

To summarise;


Solution

  • If you want to route based on the host, this is a classic feature.

    First create a service (your node application):

    service create

    Then create a route:

    create route

    route details

    Then you can test the route is matched

    curl -i --header 'kong-debug: 1' http://my-gateway-url.com:8000
    
    HTTP/1.1 502 Bad Gateway
    Date: Fri, 14 May 2021 08:11:54 GMT
    Content-Type: text/plain; charset=utf-8
    Connection: keep-alive
    Kong-Route-Id: 9f5584d7-4ac5-4720-a90c-f809c47faf8d
    Kong-Route-Name: my_gw
    Kong-Service-Id: 77443f69-80f4-49ea-b910-77eebdeb9385
    Kong-Service-Name: node_app
    Server: kong/2.0.3
    Content-Length: 58
    

    compared to

    curl -i --header 'kong-debug: 1' 0.0.0.0:8000
    HTTP/1.1 404 Not Found
    Date: Thu, 13 May 2021 20:11:23 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Content-Length: 48
    
    {"message":"no Route matched with those values"}
    

    Another thing to check is which port you cant to expose 80 or 8000, and check that the route is open on your security level (Security group on AWS for example).