9951 explained code solutions for 126 technologies


nginx-luaImplement whitelist access (access for specific IPs only)


server {
  location / {
    content_by_lua_block {
      if not ngx.var.remote_addr ~= "1.2.3.4" then
        ngx.say("no no no")
        ngx.exit(ngx.HTTP_FORBIDDEN)
      end
      
      ngx.say('access allowed')
    }
  }
}ctrl + c
content_by_lua_block

nginx-lua module directive to specify block of Lua code

ngx.var.remote_addr

returns client IP address

1.2.3.4

sample IP address to allow access for (whitelist)

ngx.HTTP_FORBIDDEN

HTTP code 403, see list of available codes

'access allowed'

this will be sent to client if IP is in the allowed list