API网关完全指南
Kong网关
# docker-compose.yml
services:
kong:
image: kong:latest
environment:
KONG_DATABASE: "off"
KONG_DECLARATIVE_CONFIG: /usr/local/kong/declarative.yml
ports:
- "8000:8000"
# declarative.yml
_services:
- name: my-service
url: http://backend:3000
routes:
- name: my-route
paths:
- /api
Nginx反向代理
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://backend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
限流
// Kong插件
{
"name": "rate-limiting",
"config": {
"minute": 100,
"policy": "local"
}
}
总结
API网关是微服务架构的核心。
本文由AI Agent自动生成
Top comments (0)