-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add kong/kong自定义默error html.md
- Loading branch information
1 parent
ed7ee2c
commit 6b1b572
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# kong 自定义默认error html | ||
|
||
## 方式一:添加默认路由并绑定request-termination 插件替换默认html | ||
|
||
**这种方式适用单个路由的单个http code替换错误页面** | ||
|
||
![image-20230726113346439](./images/kong-default-route.png) | ||
|
||
### 默认路由添加 request-termination 插件 | ||
|
||
**注意:同一个路由 同一个插件只能添加一次,下面的示例只能替换404 error 的页面** | ||
|
||
![image-20230726113655824](./images/kong-default-404-request-termination.png) | ||
|
||
## 方式二:添加 error-template-html 扩展 configmap替换默认的error template | ||
|
||
方式一的方法只能替换其中一个http code 的错误html, 不能解决其它code 问题,方式二挂载扩展configmap + 配置 error_template_html 的方式替换通用的 error template | ||
|
||
**这种方式适用替换默认的通用error template html ** | ||
|
||
### 创建error_template.html | ||
|
||
```html | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Gateway Error</title> | ||
</head> | ||
<body> | ||
<h1>Gateway Error</h1> | ||
<p>%s.</p> | ||
</body> | ||
</html> | ||
``` | ||
|
||
### 创建 configmap error-template-html | ||
|
||
```sh | ||
kubectl create configmap error-template-html --from-file=error_template.html -n kong | ||
``` | ||
|
||
### helm values 添加 error_template_html 配置 | ||
|
||
```yaml | ||
env: | ||
... | ||
error_template_html: "/kong_prefix/proxy_temp/error_template.html" | ||
... | ||
extraConfigMaps: | ||
- name: error-template-html | ||
mountPath: /kong_prefix/proxy_temp/error_template.html | ||
subPath: error_template.html | ||
``` | ||
### 更新helm | ||
```sh | ||
helm upgrade --install test kong-2.20.2.tgz --namespace kong -f values.yaml | ||
``` | ||
|
||
## 参考 | ||
|
||
https://support.konghq.com/support/s/article/How-to-create-a-catch-all-route-for-unmatched-paths?_ga=2.1458740.444088506.1690183560-1640846521.1683802307 | ||
|
||
https://docs.konghq.com/gateway/latest/reference/configuration/ | ||
|
||
https://docs.konghq.com/gateway/3.3.x/production/kong-conf/ | ||
|
||
https://github.com/Kong/kong/blob/master/kong/tools/utils.lua |