小弟是nginx新手,昨天想通过lua获取一个远程地址的返回内容。结果显示乱码。配置如下:
upstream ipquery {
server ipquery.sdo.com;
}
location ~ /getipinfo/ {
proxy_set_header Host "ipquery.sdo.com";
proxy_set_header Content-Type "text/xml; charset=utf-8";
rewrite ^/getipinfo/ /getipinfo.php?ip=60.220.232.12 break;
location ~ /testlua/ {
content_by_lua '
local res = ngx.location.capture("/getipinfo/", {method=ngx.HTTP_GET});
local status = res.status;
if status == 200 then
xmlcontent = res.body;
else
xmlcontent = "empty";
end
ngx.say(xmlcontent);
';
}
访问 /getipinfo/ 可以得到正确信息, 访问/testlua/ 则显示乱码, 求助啊~~~~~