最小实例:
nginx version: openresty/1.11.2.1
上游服务器:
server {
listen 8080 ;
server_name ~.*;
location /302 {
content_by_lua_block {
ngx.redirect("http://127.0.0.1:8119/end")
}
}
}
本地服务器:
proxy_intercept_errors on;
recursive_error_pages on;
server {
listen 8119;
server_name ~.*;
access_log logs/mytest_access.log main;
error_log logs/mytest_error.log info;
location ~ /proxyto/(.*) {
proxy_pass $1$is_args$query_string;
error_page 302 @follow_302;
}
location / {
set $origin_uri $request_uri;
proxy_pass http://ngx_up$origin_uri;
error_page 302 @follow_302;
}
location @follow_302 {
rewrite_by_lua_block {
ngx.exec("/proxyto/" .. ngx.var.upstream_http_location)
}
}
location /end {
content_by_lua_block {
ngx.say("ok")
}
}
}
============测试 ==========
问题:直接请求上游是 200 OK。 但是follow请求返回的302 但是内容是 ok的。
请问如何修改可以 follow的时候也是 200 OK?
![]()