Hello!
On Wed, Jul 9, 2014 at 9:36 AM, Sam Lee wrote:
> GET /scripts/foo/bar.lua
> I want the above request to be handled by $NGINX/scripts/foo/bar.lua
> I can add the following in nginx.conf
> location /scripts/foo/bar.lua {
> content_by_lua_file 'scripts/foo/bar.lua';
> }
> But I have many files under scripts directory. And, I want the following
> requests to be handled by respective lua files:
> GET /scripts/a.lua
> GET /scripts/b.lua
> ...
> GET /scripts/a/b/c/d.lua
Easy. Just use an nginx variable in content_by_lua. For instance,
location ~ '^/scripts/((?:[-\w]+/)*[-\w+]+\.lua)$' {
content_by_lua_file scripts/$1;
}
The kinda complicated regex for the location is to protect against
injection attacks. So be careful here and prevent using overly
permissive simple path patterns like "(.*)".
Regards,
-agentzh