Hi,
I am trying to configure Service and Route for my local service using Kong community with 0.13.1 version.
Below is the information
Upstream URL : localhost:5077/v1/vehicle/makes
To configure service I have used following commands
//------ Create Service------//
curl -i -X POST --url http://localhost:8001/services --data “name=VehicleDataQueryService” --data “protocol=https” --data “host=localhost” --data “port=5077”
//-------Create Route------//
curl -i -X POST --url http://localhost:8001/services/VehicleDataQueryService/routes --data “hosts[]=localhost” --data “paths[]=/v1/vehicle/makes”
//------- Consume API -----//
curl -i -X GET --url http://localhost:8000/v1/vehicle/makes --header “Host:localhost”
This gives me an error saying unexpected error occurred,
I am sure I miss something so that can map a route to localhost:5077 port.
Appreciate your help.
Thanks,
Keyur
Hi Keyur,
Please try using your local IP address (127.0.0.1
) instead of localhost
.
If that doesn’t work, please provide the exact error that you receive and the nginx error log.
Regards!
Hi @kikito ,
Thanks a lot for your response.
I have tried the way you suggested to use the 127.0.0.1 instead of local host.
New set of command
curl -i -X POST --url http://127.0.0.1:8001/services --data “name=VehicleDataQueryService” --data “protocol=http” --data “host=127.0.0.1” --data “port=5077”
curl -i -X POST --url http://127.0.0.1:8001/services/VehicleDataQueryService/routes --data “hosts[]=127.0.0.1” --data “paths[]=/v1/vehicle/makes”
curl -i -X GET --url http://127.0.0.1:8000/v1/vehicle/makes --header “Host:127.0.0.1”
I am running Kong on windows using docker for windows.
Here is the container log
2018/05/21 05:25:38 [error] 18#0: *4965 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: kong, request: “GET /v1/vehicle/makes HTTP/1.1”, upstream: “http://127.0.0.1:5077/ ”, host: “127.0.0.1:8000”
172.17.0.1 - - [21/May/2018:05:25:38 +0000] “GET /v1/vehicle/makes HTTP/1.1” 502 160 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36”
Though, I am new to Kong not sure how to find the NGINX error log.
I suspect its connection refused.
When I use curl command
C:\curl\I386>curl -i -X GET --url http://127.0.0.1:8000/v1/vehicle/makes --header “Host:127.0.0.1”
HTTP/1.1 502 Bad Gateway
Date: Mon, 21 May 2018 05:29:34 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/0.13.1
An invalid response was received from the upstream server
Hope this helps to investigate the issue.
Thanks,
Keyur
Your backend :
“http://127.0.0.1:5077/
Is connection refusing your proxy request. Is the back-end service up? Interesting case having nginx proxy to itself but its certainly doable because the Admin api loop-back technique within Kong is the same sort of impl.
Try curling http://127.0.0.1:5077/ directly, if that is failing then gotta work on getting your backend service functional.
shah-keyur:
172.17.0.1
Hi @jeremyjpj0916 ,
I should have mentioned that it works
http://127.0.0.1:5077/v1/vehicle/makes
that I want to upstream via
http://127.0.0.1:8000/v1/vehicle/makes
Thanks,
Keyur
Try adjusting your service to something more like this:
//------ Create Service------//
curl -i -X POST --url http://localhost:8001/services --data “name=VehicleDataQueryService” --data “protocol=https” --data “host=localhost” --data “port=5077” --data-urlencode “path=/v1/vehicle/makes”
See if that helps, although I would think router URI would -> tack onto the end of your service backend URL by default.
Hi,
I have one service hosted locally with port 5077 with resouce url is /v1/aaa/bbbb
Now I want Kong to run locally and route the request to the above up steam url.
Can you share example.
I tried from doc but not succeeded
Thanks
I have the same issue.
any solution to test kong on localhost?
i raised topic here Connect() failed (111: Connection refused) while connecting to upstream
but no success
-Rana