因为kong是基于API管理的,所以制作它的GUI是非常方便的,但是不要重复发明轮子,这里我们使用 https://github.com/PGBI/kong-dashboard 项目。关于oauth2的几种授权模式,建议读http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html。
docker-compose.yml
version: '2.1'
services:
kong-database:
image: postgres:9.5
environment:
- POSTGRES_USER=kong
- POSTGRES_DB=kong
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
kong:
image: kong:latest
command: kong start --run-migrations
depends_on:
kong-database:
condition: service_healthy
healthcheck:
test: "kong health"
interval: 10s
timeout: 5s
retries: 5
environment:
- KONG_DATABASE=postgres
- KONG_PG_HOST=kong-database
- KONG_PG_DATABASE=kong
- KONG_ADMIN_LISTEN=0.0.0.0:8001
ports:
- "8000:8000"
- "8001:8001"
- "8443:8443"
- "8444:8444"
restart: on-failure
kong-dashboard:
image: pgbi/kong-dashboard
depends_on:
kong:
condition: service_healthy
entrypoint: ./docker/entrypoint_dev.sh
ports:
- "8081:8080"
kong-java:
image: godbaby/kong-java:1.0
ports:
- "3000:3000"
参考:
- https://github.com/Kong/docker-kong/tree/master/compose
- https://github.com/PGBI/kong-dashboard/blob/3.0/docker-compose.yml
-
https://gist.github.com/oogali/0a3555b0f766dcecc104717203130f6e
注:这里的godbaby/kong-java:1.0是我们需要保护的资源服务,并配置几path有返回值。有些端口后续可以修改不暴露出来。
dashboard启动较慢,稍等1-2分钟后访问http://localhost:8081,
这里后续我们按照https://www.jianshu.com/p/814a5307632b 来操作。
1.创建service
注意host要是docker-compose对应服务的名称。
2.创建route
3.为service添加插件
{
"error_description": "The access token is missing",
"error": "invalid_request"
}