I think I've finally understood. There is global structure ngx_event_actions with add_conn/del_conn handlers which supposed to do what I want. There is only one issue (probably a bug) with add_conn handler. In version 1.2.2 with epoll usage handler add_conn never called. You should use add handler instead and check incoming parameters (event = NGX_READ_EVENT, flags = NGX_CLEAR_REQUEST). Hope it helps someone.