named location "@retry" can be on the server level only in /moss/object-routing/nginx/conf.d/access-rgws.conf:36刚才代码给我运行时报这个错误
时间: 2024-01-11 17:02:30 浏览: 153
抱歉,我之前的回答可能有误。在OpenResty中,命名的location(如"@retry")只能在server块内部使用。在您的配置文件中,您可以将"@retry"位置移到server块内部,以解决该错误。请参考下面的示例:
```lua
http {
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_next_upstream error timeout invalid_header http_502;
proxy_connect_timeout 2s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
error_page 502 = @retry;
}
location @retry {
set $upstream_failed '';
access_by_lua_block {
local upstream = require "ngx.upstream"
local upstream_name = "backend"
local servers = upstream.get_servers(upstream_name)
for _, srv in ipairs(servers) do
if srv.down then
ngx.var.upstream_failed = srv.name
else
ngx.var.upstream_failed = ''
break
end
end
}
proxy_pass http://$upstream_failed;
}
}
}
```
在这个示例中,我将"@retry"位置移动到了server块中,以确保命名的location在允许的范围内使用。请注意,这只是一个示例,您需要根据实际需求进行适当的调整。如果您仍然遇到问题,请检查您的配置文件是否正确,并确保您的OpenResty版本支持Lua模块。
阅读全文