我對Kong很陌生,並且試圖讓我對Kong的手變得很髒。 我有一個環境,其中kong(0.10)和Cassandra(最新)在單獨的碼頭集裝箱上運行。我的操作系統是macOS-Sierra 10.12.4。Kong(0.10)API設置和用法
卡桑德拉在泊塢窗:
docker run -d --name kong-database -p 9042:9042 cassandra:latest
港在泊塢窗:
docker run -d --name kong \
--link kong-database:kong-database \
-e "KONG_DATABASE=cassandra" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PG_HOST=kong-database" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 7946:7946 \
-p 7946:7946/udp \
kong
按照該Kong documentation,我通過香港的管理員API添加我的第一個API(獲取IP) 。
curl -i -X POST \
--url http://localhost:8001/apis/ \
--data 'name=example-api' \
--data 'hosts=example.com' \
--data 'upstream_url=http://httpbin.org/ip'
HTTP/1.1 201 Created
Date: Wed, 19 Apr 2017 23:39:13 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: false
Server: kong/0.10.1
{"http_if_terminated":true,"id":"9bab7ba9-f1f2-4b4d-aa9d-9966da17f94b","retries":5,"preserve_host":false,"created_at":1492645153409,"upstream_connect_timeout":60000,"upstream_url":"http:\/\/httpbin.org\/ip","upstream_send_timeout":60000,"https_only":false,"upstream_read_timeout":60000,"strip_uri":true,"name":"example-api","hosts":["example.com"]}
當我執行下面的命令來測試它,
curl -i -X GET --url http://localhost:8000/ --header 'Host: example.com'
我得到這個,
HTTP/1.1 404 NOT FOUND
Date: Wed, 19 Apr 2017 23:40:48 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 233
Connection: keep-alive
Server: gunicorn/19.7.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Via: kong/0.10.1
X-Kong-Upstream-Latency: 590
X-Kong-Proxy-Latency: 93
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
然而,當我直接curl http://httpbin.org/ip
,我得到我的IP。
如何配置Kong以獲得相同的結果?
我不記得有必要在請求URL –
明確指定的API名稱Matthias S,那麼kong proxy如何知道重定向你的調用的API? :) –
我以爲主頭是爲了這個目的。還是在v10.x中有一些突破性改變?我可以通過Kong發送請求,而無需在請求URL中指定確切的api。那麼,至少0.9.x.另外快速入門指南並沒有引用此行爲 –