Skip to content

Instantly share code, notes, and snippets.

@cr3a7ure
Forked from amgorb/lua nginx and try_files
Created March 28, 2024 21:19
Show Gist options
  • Save cr3a7ure/62900673a60526b86f6bdadd3597d139 to your computer and use it in GitHub Desktop.
Save cr3a7ure/62900673a60526b86f6bdadd3597d139 to your computer and use it in GitHub Desktop.
I have Lua script that manipulates cookies and headers based at GET parameters.
This script didnt work well at one location, strangely the ngx.var.args was empty with ordinary request.
The trick was that in location we have:
location /x/ {
header_filter_by_lua_file /etc/nginx/lua/referrer_cookie.lua;
rewrite ^/x/(.*) /$1 break;
try_files $uri /x/index.htm;
}
in which request went to index.html and all GETs got stripped. Solution was to add $args to the request:
location /x/ {
header_filter_by_lua_file /etc/nginx/lua/referrer_cookie.lua;
rewrite ^/x/(.*) /$1 break;
try_files $uri /x/index.htm$is_args$args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment