1. ngx.redirect(uri, status?) 301/302重定向
redirect 为外部重定向,
rewrite ^ /foo? redirect; # nginx config 在 rewrite 阶段重定向
等价于
return ngx.redirect('/foo'); -- Lua code
rewrite ^ /foo? permanent; # nginx config
等价于
return ngx.redirect('/foo', ngx.HTTP_MOVED_PERMANENTLY) -- Lua code
301 | Moved Permanently | 永久移动。请求的资源已被永久的移动到新URI,返回信息会包括新的URI,浏览器会自动定向到新URI。今后任何新的请求都应使用新的URI代替 |
302 | Found | 临时移动。与301类似。但资源只是临时被移动。客户端应继续使用原有URI |
2. ngx.ecex() 内部重定向
3. 子请求
res = ngx.location.capture( url ) 返回一个包含四个元素的Lua表 res.status res.header res.body res.truncated