others-How to just return a http response without proxying to backend/upstream service or serve a file in kong api gateway ?
1. Purpose
In this post, I would demonstrate how to just return a http response without proxying to backend/upstream service or serve a file in kong api gateway.
That is, when a request comes, instead of this:
We do this:
It’s useful if you want just test the performance of the kong api gateway.
2. The solution
2.1 The solution
First, goto /etc/kong
, add a file named kong.conf
or append the following line to existing kong.conf:
nginx_http_include = /etc/kong/test.conf
Then , create a file named /etc/kong/test.conf
with the following content:
server {
listen 8081;
location /test {
return 200;
}
}
Then, restart kong:
kong restart
Finally, we can test the service:
[[email protected] kong]# curl http://localhost:8081/test -vvv
* About to connect() to localhost port 8081 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8081 (#0)
> GET /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8081
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 31 Dec 2021 02:57:21 GMT
< Content-Type: text/plain; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
[[email protected] kong]#
It works!
3. Summary
In this post, I demonstrated how to add a virtual server to kong api gateway, instead of serving a file or proxying to upstream service, it just return an http response . That’s it, thanks for your reading.