HTTP Request filter module

I have a requirement for HTTP request filter. Whenever I receive a HTTP
request this filter module should read the request and does some
internal statistical work, it doesn’t manipulate the request page nor
creates response page. It just need to peep into request that’s it.
After this filter module, nginx HTTP server should continue to process
the request and serve the response to user. Can we do it without a proxy
handler, because nginx serves the responses directly here.

Please help me.

Posted at Nginx Forum:

Doesn’t post_action do what you need?
http://wiki.nginx.org/HttpCoreModule#post_action

On Thu, Nov 3, 2011 at 3:06 PM, forum_id [email protected] wrote:

I have a requirement for HTTP request filter. Whenever I receive a HTTP
request this filter module should read the request and does some
internal statistical work, it doesn’t manipulate the request page nor
creates response page. It just need to peep into request that’s it.
After this filter module, nginx HTTP server should continue to process
the request and serve the response to user. Can we do it without a proxy
handler, because nginx serves the responses directly here.

I think this is a perfect use case for the rewrite_by_lua or
access_by_lua directives provided by the ngx_lua module. See

Lua | NGINX

You can read and modify the request URI, query args, or even request
bodies in your Lua code and save the statistical results in the
shm-based dictionary (shared_dict) provided by ngx_lua or issue a
subrequest from within Lua to internal locations configured by
ngx_memc or ngx_redis2 via the ngx.location.capture API.

Because LuaJIT 2.0 is so light and so fast, this setting can achieve
performance comparable with an Nginx C module and also provide
scripting flexibility :slight_smile:

Regards,
-agentzh

Thank you. I am new to nginx, so spare me if I talk anything nonsense. I
want through link you provided, and then went through code as well. I
couldn’t understand few things here

  1. Can we override nginx core’s directive?
  2. Since that post action is been used in multiple place, how far it
    safe to over write it?

Thank you once again.

Posted at Nginx Forum:

On Thu, Nov 3, 2011 at 8:13 PM, forum_id [email protected] wrote:

Thank you. As per the project requirements need to develop C modules
only, so if @agentzh can suggest me in this way, that would be helpful.

Just take a look at how ngx_lua does those things on the C level :slight_smile:

Regards,
-agentzh

@agentzh, thank you. As you suggested, I went through the ngx_lua code.
Since I am new to nginx, my understanding was not so good, but I want to
write it in few points,

  1. Lua handler receives request
  2. Forwards request to Lua interpreter
  3. Send Lua response back to user.

Let me know if my understanding itself is wrong. Give me some simple
pointers to understand, because I need to start with my module as soon
as possible. Thank you once again.

Posted at Nginx Forum:

On Fri, Nov 4, 2011 at 6:50 PM, forum_id [email protected] wrote:

@agentzh, thank you. As you suggested, I went through the ngx_lua code.
Since I am new to nginx, my understanding was not so good, but I want to
write it in few points,

If you’re not familiar with Nginx internals, then I think use ngx_lua
and Lua scripting is the quickest and easiest way to get the job done.
I don’t think I have the time to explain every thing here because it’s
really complicated for freshmen :slight_smile:

If you insist in Nginx C module development, I suggest you start with
the resources listed here:

http://wiki.nginx.org/Resources

Regards,
-agentzh

Thank you. As per the project requirements need to develop C modules
only, so if @agentzh can suggest me in this way, that would be helpful.

Posted at Nginx Forum:

@agentzh, thank you. Even though I am new to nginx I went through to
understand how nginx works and understood how nginx modules work. I just
need very few pointers, like lua modules receives request and forwards
to lua interpreter, after processing the request how it sends details. I
need to overall details not complete in depth details, so that I can
spend more time on code in productive way. It will make easy to
understand in better way. I need to use C language. Please give very
small notes with 5 points are also fine for me to start on it.

Posted at Nginx Forum: