Hi guys!

I am glad to announce that the new development version of
ngx_openresty, 1.4.2.1, is now released:

    http://openresty.org/#Download

Below is the complete change log for this release, as compared to the
last (devel) release, 1.4.1.3:

 *   upgraded the Nginx core to 1.4.2.

     *   see <http://nginx.org/en/CHANGES-1.4> for changes.

 *   upgraded LuaRestyDNSLibrary to 0.10.

     *   feature: now we return all the answer records even when the
         DNS server returns a non-zero error code, in which case the
         error code and error string are now set as the "errcode" and
         "errstr" fields in the Lua table returned. thanks Matthieu
         Tourne for requesting this.

The HTML version of the change log with some helpful hyper-links can
be browsed here:

    http://openresty.org/#ChangeLog1004002

We have run extensive testing on our Amazon EC2 test cluster and
ensured that all the components (including the Nginx core) play well
together. The latest test report can always be found here:

    http://qa.openresty.org

Enjoy!
-agentzh
    春哥,你好!
    在做nginx模块开发时,遇到一个比较郁闷的问题,向你请教。
    在做nginx模块时,在init_process方法中,我使用了所有方法或者宏都没办法获取到 location_config 配置。
     
    static ngx_int_t ngx_http_rtdef_init_process(ngx_cycle_t *cycle)  这样的方法中,系统中已知的一个宏是
    #define ngx_http_cycle_get_module_main_conf(cycle, module)                    \
        (cycle->conf_ctx[ngx_http_module.index] ?                                 \
            ((ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index])      \
                ->main_conf[module.ctx_index]:                                    \
            NULL)
    可以获取main_config 我依照同样的写法写了个ngx_http_cycle_get_module_loc_conf
    #define ngx_http_cycle_get_module_loc_conf(cycle, module)                    \
        (cycle->conf_ctx[ngx_http_module.index] ?                                 \
            ((ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index])      \
                ->loc_conf[module.ctx_index]:                                    \
            NULL)
    # 测试表明这种写法是错误的。。
     
    static ngx_int_t ngx_http_rtdef_init_process(ngx_cycle_t *cycle)
    {
    ngx_http_rtdef_loc_conf_t* loccfg = (ngx_http_rtdef_loc_conf_t*)ngx_http_cycle_get_module_loc_conf(cycle, ngx_http_rtdef_module);
    # 这里获取到的不对。
    ...
    }
     
    但是获取到的配置不是正确的,地址都不对,请问有什么办法在init_process方法中获取到我的模块的正确的 location_config。
      Hello!
      
      2013/8/12 jie123108:
      > 在做nginx模块开发时,遇到一个比较郁闷的问题,向你请教。
      > 在做nginx模块时,在init_process方法中,我使用了所有方法或者宏都没办法获取到 location_config 配置。
      >
      
      init_process 是 worker 进程全局的回调,其运行上下文并不与任何 server {} 配置块相关联,自然也不与任何
      location {} 配置块相关联。所以,你需要自己决定到底选择哪一个 server {} 的配置,抑或是你自己创建一个假的 conf
      占位。
      
      Regards,
      -agentzh
      
        非常感谢春哥的回复,看来通过cycle是不好获取到location配置了。 
        我之前的做法是在模块内使用一个静态变量来记住这个location配置,然后在init_process里面使用,因为觉得这样不太幽雅,所以才有了这封邮件。 看来目前也只能使用这种不太幽雅的方式了。
         

        jie123108
         
        发送时间: 2013-08-13 07:12
        收件人: openresty
        主题: Re: [openresty] 关于nginx模块开发时,在init_process方法中获取location_config配置的问题。
        Hello!
         
        2013/8/12 jie123108:
        > 在做nginx模块开发时,遇到一个比较郁闷的问题,向你请教。
        > 在做nginx模块时,在init_process方法中,我使用了所有方法或者宏都没办法获取到 location_config 配置。
        >
         
        init_process 是 worker 进程全局的回调,其运行上下文并不与任何 server {} 配置块相关联,自然也不与任何
        location {} 配置块相关联。所以,你需要自己决定到底选择哪一个 server {} 的配置,抑或是你自己创建一个假的 conf
        占位。
         
        Regards,
        -agentzh
         
        -- 
        -- 
        邮件来自列表“openresty”,专用于技术讨论!
        订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
        发言: 请发邮件到 openresty@googlegroups.com
        退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
        归档: http://groups.google.com/group/openresty
        官网: http://openresty.org/
        仓库: https://github.com/agentzh/ngx_openresty
        教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
          Hello!
          
          2013/8/12 jie123108:
          > 非常感谢春哥的回复,看来通过cycle是不好获取到location配置了。
          > 我之前的做法是在模块内使用一个静态变量来记住这个location配置,然后在init_process里面使用,因为觉得这样不太幽雅,所以才有了这封邮件。
          > 看来目前也只能使用这种不太幽雅的方式了。
          >
          
          在 nginx 加载配置的阶段使用全局变量是有风险的。因为会存在 HUP reload 中途失败的情形,此时 nginx
          仍然使用原先的老配置。要小心这种情况导致的数据状态不一致。
          
          Regards,
          -agentzh
          
            恩,多谢提醒。这点之前倒是没想到。 这样只能尽量避免这种用法了,或者使用了之后避免reload这种重启方法了。
             

            jie123108
             
            发送时间: 2013-08-13 10:05
            收件人: openresty
            主题: Re: Re: [openresty] 关于nginx模块开发时,在init_process方法中获取location_config配置的问题。
            Hello!
             
            2013/8/12 jie123108:
            > 非常感谢春哥的回复,看来通过cycle是不好获取到location配置了。
            > 我之前的做法是在模块内使用一个静态变量来记住这个location配置,然后在init_process里面使用,因为觉得这样不太幽雅,所以才有了这封邮件。
            > 看来目前也只能使用这种不太幽雅的方式了。
            >
             
            在 nginx 加载配置的阶段使用全局变量是有风险的。因为会存在 HUP reload 中途失败的情形,此时 nginx
            仍然使用原先的老配置。要小心这种情况导致的数据状态不一致。
             
            Regards,
            -agentzh
             
            -- 
            -- 
            邮件来自列表“openresty”,专用于技术讨论!
            订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
            发言: 请发邮件到 openresty@googlegroups.com
            退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
            归档: http://groups.google.com/group/openresty
            官网: http://openresty.org/
            仓库: https://github.com/agentzh/ngx_openresty
            教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
              Write a Reply...