当前位置:网站首页>Gateway Kong route adding instructions
Gateway Kong route adding instructions
2022-07-19 01:21:00 【Magic pen code beautiful】
1. Preface
Gateways have been used in recent projects Kong, In the process of deploying services and routing , Encountered some requests, and the result returned is html page , adopt js send out ajax When asked , If the proxy service is not configured to cross domain request , Will appear unable to pass js Cooperation request header Host Requested questions .
In the follow-up study Kong In the process of official documents , Find out , When adding a route, you can use Request header 、 Request path Etc .
2 Routing configuration
2.1 Request header routing
adopt Host The request header route is Kong agent The most direct way of flow , and This is a Http Host Intended use of headers .
adopt Admin API When adding a route ,hosts Multiple values can be received :
curl -i -X POST http://localhost:8001/routes/ \
-H 'Content-Type: application/json' \
-d '{"hosts":["example.com", "foo-service.com"]}'
HTTP/1.1 201 Created
...
Client's Request header contain Host: example.com perhaps Host: foo-service.com Will access specific services through this route .
2.2 Other request header routes
from 1.3 Start ,Kong Support through arbitrary HTTP Header for routing , By adding custom in the request header header Routing .
Add custom Request header mode :
curl -i -X POST \
--url http://kong:8001/services/{
serviceId}/routes \
--data "name=kong.route.client" \
--data "headers.client=kong" \
--data 'paths=/client'
After successful addition , Request from client The header contains Client:Kong Will pass kong.route.client Route to specific services
2.3 Access path routing
kong Another way of route matching is through the request path . adopt Admin API When adding a route , To realize the function of routing through the request path , When adding , Can not add Host Request header .
How to add :
curl -i -X POST \
--url http://kong:18001/services/{
servcieId}/routes \
--data "name=kong.route.path" \
--data 'paths=/kong' \
--data 'strip_path=false'
The above configuration , Request from client With /kong/*** Path at the beginning Specific services will be accessed through this road .
strip_path Parameter description :
strip_path Use Boolean The value of the property ,
Set to ture when , After matching the request of the client , Prefix of configuration The information will not be included in the upstream request . As configured above ,strip_path=true when , Access from the client /kong/services/list When forwarding to the upstream service, it will be /service/list . Routing configuration route /kong Prefix will not be included in Upstream request .
Route by path , To solve Some client requests cannot be added host The way of the header .
边栏推荐
猜你喜欢

CobalStrike的部署(附带资源)

Mathematics 03 derivative and differential (to be supplemented)

Watermelon book chapter 4

How typora inserts tables

Detailed explanation of groupby

深度之眼三——(7)】数学:svd分解的应用

Recording multiple environments at a time leads to code bugs

好看的(动态)Jay迷自制动态专辑卡片(正面和背面不同)和歌词页面

The logical architecture of MySQL
![[MySQL] Error 1130 problem solution](/img/75/6fcb13bbfa4f75615a1e7c2e317ca9.png)
[MySQL] Error 1130 problem solution
随机推荐
应用密码学总结
Mathematics 03 derivative and differential (to be supplemented)
Oracle自动存储管理18c分步安装-2
[set] common methods of operating ArrayList set
flask 快速搭建一个API
1. Sum of two numbers
flutter 项目 ScrollController attached to multiple scroll views,Failed assertion: line 109 pos 12 报错处理
Mathématiques 03 dérivées et différentielles (à compléter)
Day04-路由层
数学基础02——数列极限
Swagger
數學03-導數與微分(待補)
Markdown各种数学符号
Pytoch uses NN to realize softmax regression
CLI and vite realize cross domain through proxy
Factorybean usage scenario
Day06-ORM字段及操作
Pytoch implements linear regression manually
Tool code
深度之眼三——(4,5)】数学:矩阵特征值与特征向量2