我是 Kong 的新手,我正试图弄脏 Kong。我有一个 kong (0.10) 和 Cassandra (latest) 在单独的 docker 容器上运行的环境。我的操作系统是 macOS -Sierra 10.12.4。
码头工人中的卡桑德拉:
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 文档,我通过 Kong Admin 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>
但是,当 i 直接时curl http://httpbin.org/ip
,我会得到我的 IP。
如何配置 Kong 以获得相同的结果?