【问题标题】:Apache apisix routing configurationApache apisix 路由配置
【发布时间】:2022-12-29 15:09:01
【问题描述】:

我是 apache APISIX 的新手,我想在 Apache APISIX 网关中配置路由。首先我关注了APISIX官方文档。在该文档中,他们使用“httpbin.org:80”作为上游服务器。它对我有用,如果我设置在我的本地主机(127.0.0.1)中运行的上游新上游服务器,它对我不起作用。它抛出一个错误的网关错误(502)

如果有人知道解决此问题的答案,请告诉我。

{
    "methods": [
        "GET"
    ],
    "host": "example.com",
    "uri": "/anything/*",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "httpbin.org:80": 1
        }
    }
}

上面的路由配置对我有用。这是 API 网关 (http://127.0.0.1:9080/anything/*) 将请求路由到 http://httpbin.org:80/anything/*)

{
    "methods": [
        "GET"
    ],
    "host": "example.com",
    "uri": "/anything/*",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:3001": 1
        }
    }
}

在上面的配置中,我已经将路由配置为服务并且该服务正在我的本地计算机上运行,​​该端口是 30001。现在如果我调用 API (http://127.0.0.1:9080/anything/*) 它不会将我的请求路由到服务器 (@ 987654324@),而是抛出错误的网关错误。

const http = require('http')

const hostname = '127.0.0.1'
const port = 3001

const server = http.createServer((req, res) => {
  res.statusCode = 200
  res.setHeader('Content-Type', 'text/plain')
  res.end('Hello World\n')
})

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`)
})

这里上面的代码是我的后端服务器,它作为上游服务器运行。

如果您知道调试坏网关异常的答案,请告诉我。

【问题讨论】:

    标签: keycloak apache-apisix


    【解决方案1】:

    你能确认你首先使用的是哪个端口吗,因为你在描述中使用的是 3001 而不是 30001;然后尝试直接访问它而不是使用网关代理它来检查它是否可以访问。

    【讨论】:

      【解决方案2】:

      我遇到了确切的问题。

      我假设您正在使用 docker-compose 或 docker 部署 APISIX(在其官方文档中推荐使用)。

      docker 应用程序在名为 apisix 的 docker 网桥网络上运行。这就是 APISIX 无法访问您的本地主机应用程序的原因。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-22
        • 1970-01-01
        • 2017-06-19
        • 1970-01-01
        • 2016-04-13
        • 2022-07-14
        • 2021-05-06
        • 1970-01-01
        相关资源
        最近更新 更多