以下是我的配置:
server {
server_name www.xxx.com;
location ~* ^/(unstable|staging|prod)-console/ {
set $serverip "";
rewrite_by_lua '
if string.find(ngx.var.uri, "unstable") ~= nil then
ngx.var.serverip = "10.17.21.123"
elseif string.find(ngx.var.uri, "staging") ~= nil then
ngx.var.serverip = "10.17.21.123"
elseif string.find(ngx.var.uri, "prod") ~= nil then
ngx.var.serverip = "10.17.21.123"
end
';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://$serverip:1234;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
当我访问匹配此位置的页面时,它给出了500错误。在nginx错误日志中,它显示2017/03/17 15:11:19 [error] 2638#2638: *6 no host in upstream ":1234", client: 10.19.35.20, server: console.allinmoney.com, request: "GET /unstable-console/?arg=ifconfig HTTP/1.1", host: "console.allinmoney.com"
。这意味着变量在lua脚本中没有正确更改。有人可以为此提供帮助吗?感谢