So is "rewrite_by_lua" also evil?

agentzh agentzh at gmail.com
Thu Oct 13 01:34:28 UTC 2011


On Thu, Oct 13, 2011 at 2:35 AM, Nginx User <nginx at nginxuser.net> wrote:
> if ($request_method !~* (GET|HEAD|POST) ) {
>        return 400;
> }
>
> ... while this sends php files as text downloads ...
>
> rewrite_by_lua '
>        method =  ngx.re.match(ngx.var.request_method, "GET", "i")
>        if method == nil then
>                method =  ngx.re.match(ngx.var.request_method, "POST", "i")
>                if method == nil then
>                        method =  ngx.re.match(ngx.var.request_method, "HEAD", "i")
>                        if method == nil then
>                                ngx.exit(ngx.HTTP_BAD_REQUEST)
>                        end
>                end
>        end
> ';

BTW, you could have written the Lua code like this:

local m = ngx.re.match(ngx.var.request_method, "GET|POST|HEAD", "io")
if not m then
    ngx.exit(400)
end

The ngx.re.match uses the same PCRE engine as ngx_rewrite's "if"
anyway. Also, because the regex argument is a constant here, the "o"
flag can be specified to cache the compiled regex object on the global
level.

>
> See debug output: http://pastebin.com/A7LNeCf0
>

The debug log data you've provided contains a lot of references to the
location @pretty_urls which is missing from your original nginx.conf
snippet. Could you please provide a minimized but complete nginx.conf
that can reproduce this problem as well as the corresponding debug.log
snippet?

Thanks!
-agentzh



More information about the nginx mailing list