subrequest示例

来源:互联网 发布:淘宝快递打印机设置 编辑:程序博客网 时间:2024/06/05 15:24

访问/query?s_sh000001时,访问http://hq.sinajs.cn

配置文件中子请求的设置

location /list{    //决定访问的上游服务器地址是hq.sinajs.cn    proxy_pass http://hq.sinajs.cn;    //不希望第三方服务发来的http包体进行过gzip压缩    proxy_set_header Accept-Ecoding "";}当然,处理/query开头的URI用户请求还需要使用自己的模块    location /query{        mytest;    }

请求上下文

此处仅用于保存子请求回调方法中解析出来的数据

typedef struct{    ngx_str_t stock[6];}ngx_http_mytest_ctx_t;

子请求结束时的处理方法

定义mytest_subrequest_post_handler作为子请求结束时的回调方法
在其中设置父请求的回调方法

父请求的回调方法

启动subrequest

在处理用户请求的ngx_http_mytest_handler中创建subrequest子请求

0 0
原创粉丝点击