【发布时间】: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}/`)
})
这里上面的代码是我的后端服务器,它作为上游服务器运行。
如果您知道调试坏网关异常的答案,请告诉我。
【问题讨论】: