drrrMikado commented on issue #5233:
URL: https://github.com/apache/apisix/issues/5233#issuecomment-1022053212
I get same error in custom plugin when rewrite upstream.
Upstream data:
```json
{
"id": "ups-sys1-abcd",
"create_time": 1643165083,
"update_time": 1643190928,
"nodes": [
{
"host": "example.com",
"port": 80,
"weight": 1
}
],
"type": "roundrobin",
"hash_on": "vars",
"scheme": "http",
"pass_host": "pass",
"name": "ups-sys1-abcd"
}
```
Route:
```json
{
"id": "1",
"create_time": 1643186095,
"update_time": 1643187397,
"uri": "/get",
"name": "",
"methods": [
"GET"
],
"host": "sys1.com",
"plugins": {
"custom-plugin": {}
},
"upstream": {
"nodes": [
{
"host": "httpbin.org",
"port": 80,
"weight": 1
}
],
"type": "roundrobin",
"hash_on": "vars",
"scheme": "http",
"pass_host": "pass"
},
"status": 1
}
```
Custom plugin code:
```lua
function _M.rewrite(conf, ctx)
-- rewrite by request header
-- get upstream info
local upstreams = core.config.fetch_created_obj("/upstreams")
if not upstreams then
return core.response.exit(502)
end
-- new upstream id by system name and tag
local upstream_id = "ups-sys1-abcd"
local ups_info = upstreams:get(tostring(upstream_id))
if not ups_info then
return
end
ups_info = ups_info.value
upstream.set(ctx, ups_info.name, ctx.conf_version, ups_info)
end
```
error log:
```
apisix | 2022/01/26 09:11:48 [error] 48#48: *456684 [lua]
balancer.lua:353: run(): failed to set server peer [example.com:80] err: no
host allowed while connecting to upstream, client: 172.18.0.1, server: _,
request: "GET /get HTTP/1.1", host: "sys1.com"
```
--
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]