Matching a href spec with Lua regex
vamshi
nginx-forum at nginx.us
Fri Jun 27 17:03:29 UTC 2014
Sorry for the double post, but wanted to post the complete conf ... just in
case there was a mistake
server {
listen 80;
server_name 127.0.0.1 10.0.9.44;
set $_ActualTarget "";
location / {
rewrite_by_lua '
local _args = ngx.req.get_uri_args()
ngx.var._ActualTarget = _args["_url_"];
_args["_url_"] = nil
print(ngx.var._ActualTarget)
ngx.req.set_uri_args(_args);
';
resolver 8.8.8.8;
proxy_pass_request_body on;
proxy_pass_request_headers on;
proxy_pass $scheme://$_ActualTarget;
header_filter_by_lua '
ngx.header.content_length = nil
ngx.header.set_cookie = nil
if ngx.header.location then
local _location = ngx.header.location
_location = ngx.escape_uri(_location)
_location = "http://10.0.9.44/?_url_=" .. _location
ngx.header.location = _location
end
';
body_filter_by_lua '
local escUri = function (m)
local _str = "href=\\"http://10.0.9.44/?_url_="
_str = _str .. ngx.escape_uri(m[1]) .. "\\""
return _str
end
local newStr, n, err = ngx.re.gsub(ngx.arg[1],
"href=\\"(.*)\\"", escUri, "ijox")
print(ngx.arg[1])
';
}
#
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251234,251245#msg-251245
More information about the nginx
mailing list