content_by_lua
server { listen 80; server_name lua.luckybing.top; location / { default_type ‘text/plain‘; content_by_lua ‘ if ngx.var.remote_addr=="203.100.83.125" then ngx.say("hello,from yunxiao") else ngx.say("hello,from other") end‘; } }
rewrite_by_lua
server { listen 80; server_name lua.luckybing.top; location / { rewrite_by_lua ‘ if ngx.var.remote_addr=="203.100.83.125" then return ngx.redirect("http://www.luckybing.top", 302) else return ngx.redirect("http://chat.luckybing.top", 302) end‘; } }
access_by_lua
server { listen 80; server_name lua.luckybing.top; location @client{ proxy_pass http://www.baidu.com; } location / { access_by_lua ‘ if ngx.var.remote_addr=="203.100.83.125" then ngx.exit(ngx.HTTP_FORBIDDEN) else ngx.exec("@client") end‘; } }
rewrite_by_lua
server { listen 80; server_name lua.luckybing.top; location @client{ proxy_pass http://47.95.222.240:3000; } location @client2{ proxy_pass http://47.95.222.240:4000; } location / { default_type ‘text/html‘; #ngx.var.remote_addr rewrite_by_lua ‘ myIP = ngx.req.get_headers()["X-Real-IP"] if myIP == nil then myIP = ngx.req.get_headers()["x_forwarded_for"] end if myIP == nil then myIP = ngx.var.remote_addr end if myIP=="203.100.83.125" then ngx.exec("@client2") else ngx.exec("@client") end‘; } }