Chinaunix首页 | 论坛 | 博客
  • 博客访问: 136778
  • 博文数量: 34
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 252
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-27 20:04
文章分类

全部博文(34)

文章存档

2018年(1)

2017年(23)

2016年(10)

我的朋友

分类: 系统运维

2017-06-06 13:52:28

需求:

把客户端投递到生产环境的服务的请求转发到测试环境的服务,使用nginx版本为openresty,普通nginx需要加载lua模块

 ,

 

1. nginx.conf

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    #gzip  on;

        upstream backend {

            #server 119.254.61.141:10061;

            server 127.0.0.1:10061;

            keepalive 100;

    }

   

    server {

        listen       80;

        server_name  localhost;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

       location ~ /proxy/(.*) {

            internal;

            proxy_pass

         }

        ##############################################################

 

        location = /test {

            content_by_lua '

                ngx.req.read_body()

                local args = ngx.req.get_post_args()

                for key, val in pairs(args) do

                    if val == "deviceid" then

                        local resp = ngx.location.capture("/proxy/search", {

                                method = ngx.HTTP_POST,

                            body = body,

                                args = {q = "hello"}

                           })

                           --获取状态码

                            ngx.status = resp.status

 

                            --获取响应头

                            for k, v in pairs(resp.header) do

                        if k ~= "Transfer-Encoding" and k ~= "Connection" then

                                    ngx.header[k] = v

                                end

                            end

                           if resp.body then

                                ngx.say(resp.body)

                            else

                                ngx.say("======NO BODY=========")

                            end

                          

                    else

                        ngx.say(key, ": ", val)

                    end

                end

        ';

        }      

 

2.本地启动端口服务,等待监听

 


 

3. 启动nginx服务

nginx.exe -c conf/nginx.conf

4.client端发送POST请求


 

5.查看本地监听的服务端口,可以看到数据有接收到


 

 

6.可以再用实际的服务测试,看是否有数据 返回到client

阅读(3396) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~