Last active
October 23, 2018 18:08
-
-
Save ckolos/e9c10c6ec5ef5e344d33674627b3f099 to your computer and use it in GitHub Desktop.
rewrite_xff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| header_filter_by_lua_block { | |
| function get_xff(s, delimiter) | |
| result = {}; | |
| for match in (s..delimiter):gmatch("(.-)"..delimiter) do | |
| table.insert(result, match); | |
| end | |
| return result[#result]; | |
| end | |
| xff = ngx.req.get_headers()["X-Forwarded-For"] | |
| ngx.req.clear_header("X-Forwarded-For") | |
| new_xff = get_xff(xff, ",") | |
| ngx.req.set_header("X-Forwarded-For", new_xff) | |
| } |
Author
header_filter_by_lua_block {
local xff = ngx.req.get_headers()["X-Forwarded-For"]
ngx.req.clear_header("X-Forwarded-For")
local new_xff = string.match(xff, ",? *([^,]+)$")`
ngx.req.set_header("X-Forwarded-For", new_xff)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.