首页 > 其他 > 详细

lua_nginx_module用例

时间:2018-03-01 12:20:22      阅读:251      评论:0      收藏:0      [点我收藏+]

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;
        } 
    }

 

lua_nginx_module用例

原文:https://www.cnblogs.com/xbblogs/p/8487623.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!