SylviaBABY commented on code in PR #7022: URL: https://github.com/apache/apisix/pull/7022#discussion_r870013813
########## docs/zh/latest/getting-started.md: ########## @@ -210,114 +255,34 @@ curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H "X-API-KEY: edd1c9f034335f }' ``` -## 第三步:验证 - -我们已创建了路由与上游服务,并将它们进行了绑定。现在让我们访问 Apache APISIX 来测试这条路由: +我们已经创建了路由与上游服务,现在可以通过以下命令访问上游服务: ```bash curl -i -X GET "http://127.0.0.1:9080/get?foo1=bar1&foo2=bar2" -H "Host: httpbin.org" ``` -它从我们的上游服务(实际是 `httpbin.org`)返回数据,并且结果符合预期。 - -## 进阶操作 - -本节提供了 Apache APISIX 的一些进阶操作技巧,包括:添加身份验证、为路由添加前缀、使用 APISIX Dashboard 以及常见问题排查。 - -### 添加身份验证 - -我们在第二步中创建的路由是公共的,只要知道 Apache APISIX 对外暴露的地址,**任何人** 都可以访问这个上游服务,这种访问方式没有保护措施,存在一定的安全隐患。在实际应用场景中,我们需要为路由添加身份验证。 - -现在我们希望只有特定的用户 `John` 可以访问这个上游服务,需要使用 [消费者(Consumer)](./terminology/consumer.md) 和 [插件(Plugin)](./terminology/plugin.md) 来实现身份验证。 - -首先,让我们用 [key-auth](./plugins/key-auth.md) 插件创建一个 [消费者(Consumer)](./terminology/consumer.md) `John`,我们需要提供一个指定的密钥: - -```bash -curl "http://127.0.0.1:9080/apisix/admin/consumers" -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" -X PUT -d ' -{ - "username": "john", - "plugins": { - "key-auth": { - "key": "key-of-john" - } - } -}' -``` - -接下来,让我们绑定 `消费者(John)` 到路由上,我们只需要为路由 **启用** [key-auth](./plugins/key-auth.md) 插件即可。 - -```bash -curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" -X PUT -d ' -{ - "uri": "/get", - "host": "httpbin.org", - "plugins": { - "key-auth": {} - }, - "upstream_id": "1" -}' -``` - -现在当我们访问第二步创建的路由时,会触发 **Unauthorized Error(未经授权的错误)**。 - -访问那个路由的正确方式是添加一个带有正确密钥的名为 `apikey` 的 `Header`,如下方代码所示。 - -```bash -curl -i -X GET http://127.0.0.1:9080/get -H "Host: httpbin.org" -H "apikey: key-of-john" -``` - -### 为路由添加前缀 - -现在,假设您要向路由添加前缀(例如:samplePrefix),并且不想使用 `host` 头, 则可以使用 `proxy-rewrite` 插件来完成。 - -```bash -curl "http://127.0.0.1:9080/apisix/admin/routes/1" -H "X-API-KEY: edd1c9f034335f136f87ad84b625c8f1" -X PUT -d ' -{ - "uri": "/samplePrefix/get", - "plugins": { - "proxy-rewrite": { - "regex_uri": ["^/samplePrefix/get(.*)", "/get$1"] - }, - "key-auth": {} - }, - "upstream_id": "1" -}' -``` +该请求将被 APISIX 转发到 `http://httpbin.org:80/anything/foo?arg=10`。 -现在您可以使用以下命令来调用路由: +## APISIX Dashboard -```bash -curl -i -X GET "http://127.0.0.1:9080/samplePrefix/get?param1=foo¶m2=bar" -H "apikey: key-of-john" -``` +你还可以使用 APISIX Dashboard 创建和配置类似于上述步骤中所创建的路由。 -### APISIX Dashboard +如果你已经完成上述操作步骤,就可以通过 [`localhost:9000`](http://localhost:9000/) 访问 APISIX Dashboard。 -Apache APISIX 提供了一个 [Dashboard](https://github.com/apache/apisix-dashboard),让我们的操作更直观更轻松。 +单击侧边栏中的 [Route](http://localhost:9000/routes/list),可以查看已经配置的路由列表。你也可以看到在上述步骤中使用 Admin API 创建的路由。 - +你也可以通过单击 [Create](http://localhost:9000/routes/create) 按钮并按照提示创建新路由: -<!-- -# -# In addition to the basic Markdown syntax, we use remark-admonitions -# alongside MDX to add support for admonitions. Admonitions are wrapped -# by a set of 3 colons. -# Please refer to https://docusaurus.io/docs/next/markdown-features/admonitions -# for more detail. -# ---> + -### 常见问题排查 +新创建的路由将被添加到路由列表中: -- 确保所需的所有端口(**默认的 9080/9443/2379**)未被其他系统/进程使用。 + - 下面是终止正在侦听特定端口(基于 unix 的系统)的进程的命令。 +想要了解更多关于 APISIX Dashboard 的信息,请参考 [APISIX Dashboard 文档](/docs/dashboard/USER_GUIDE)。 - ```bash - sudo fuser -k 9443/tcp - ``` +## 后续步骤 Review Comment: ```suggestion ## 总结 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
