Skip to content

Instantly share code, notes, and snippets.

@maZahaca
Last active September 19, 2017 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maZahaca/9a90e9b5d1bc6376097172a8a14ed7e9 to your computer and use it in GitHub Desktop.
Save maZahaca/9a90e9b5d1bc6376097172a8a14ed7e9 to your computer and use it in GitHub Desktop.
Just an example of LUA block in NGINX conf for preventing unnecessary traffic
server {
     location / {
        client_max_body_size 100k;
        client_body_buffer_size 100k;

        access_by_lua_block {
            -- check the client IP address is in our black list
            if ngx.var.remote_addr == "132.5.72.3" then
                ngx.exit(ngx.HTTP_FORBIDDEN)
            end

            -- check if the URI contains bad words
            if ngx.var.uri and
                   string.match(ngx.var.request_body, "evil")
            then
                return ngx.redirect("/terms_of_use.html")
            end

            -- tests passed
        }

        # proxy_pass/fastcgi_pass/etc settings
     }
 }

#lua #nginx This example was taken from the official Lua documentation in here: https://github.com/openresty/lua-nginx-module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment