Further "Hacking" the event model of Nginx

Hi all,

I have read the following post.
http://www.ruby-forum.com/topic/149417
It is helpful, I am new to nginx and need some instructions on my work.

We have 3 machines, server MASTER is the application server visible to
client. server WORK1 and server WORK2 is the task processing server. the
request sequence is like this:

  1. client
    -send request

  2. nginx server MASTER:
    -receive request
    -extract useful information from request
    -post the re-structured extract data to nginx server WORK1

  3. nginx server WORK1:
    -receive the request
    -process…
    -send back response

  4. nginx server MASTER:
    -receive the response from WORK1
    -post the response data to nginx server WORK2

  5. nginx server WORK2:
    -receive the request
    -process…
    -send back response

  6. nginx server MASTER:
    -receive the response from WORK2
    -send back the response data to client

Can anyone help me on where to hack on nginx that can suit my scenario.

Regards,
Vincent

you really need to specify more details about what you are doing. is
that HTTP? what are you processing, maybe you don’t need to hack
anything, depending on what you do with the request…

Mauro Stettler wrote:

you really need to specify more details about what you are doing. is
that HTTP? what are you processing, maybe you don’t need to hack
anything, depending on what you do with the request…
Thanks for your help;-)
yes, it is HTTP. Our business logic is split into multiple tasks, they
are deployed on multiple backend servers. We have a master server
visible to the client. The master server need read client post data
,modify the data and send to backend server1, the backend server1 also
have nginx running, it should do a time consuming task. The master
server received the response from backend server1 and send back to
backend server2. backend server2 also do a time consuming task. the
master server received the response and send back the client.
By now, I have the following design:

the master server handle the client request, it will modify the post
body and bypass request to backend server1.(I may need to learn code in
proxy_module and fastcgi_module)
problem:
How can I hook the response send back from backend server1? Can I use
body filter module so that I can get the response body and send to
backend server2 again?

the backend server logic is simple, it will invoke functions in dll.
problem:
the functions in dll is time consuming, Will it block the nginx?

Thanks again;-)

to be able to receive the request of one backend, process it, and then
go to the next one, i think this will help you:
http://github.com/vkholodkov/nginx-eval-module

for getting the post value this might help:

http://github.com/calio/form-input-nginx-module

Mauro Stettler wrote:

to be able to receive the request of one backend, process it, and then
go to the next one, i think this will help you:
http://github.com/vkholodkov/nginx-eval-module

for getting the post value this might help:

http://github.com/calio/form-input-nginx-module

Thanks for your kind help;-)

I have download and looked into nginx-eval-module. It seems that the
module can send sub request to backend only once. when the response is
sent back from the backend, the module only can modify the response
body…(maybe I should try remove the response from the body chain and
send to another backend, I will try this;-) )

The task to extract post value/head is finished. The remaining problem
is that my handler is time consuming and it may block nginx work
process, I need to try the way in http://www.ruby-forum.com/topic/149417

Thanks again;-)

Hey,

Wouldn’t http://wiki.nginx.org/NginxXSendfile work for bouncing your
request between servers without modifying source code (thats how I do
it) ?

Cheers,
Johan

Hello,

On 16 jul 2010, at 09.33, Vincent Huang wrote:

Thanks for your help.
I need hold the response from one backend and send it to another(not
directory use the backed response as the result to client), so I have to
write some code inside nginx…
Thanks again;-)

The example might be a bit misleading in your case. What
X-Accel-Redirect does is take precedence over the location uri. You
don’t specifically have to pass the location match to a directory for
downloads, you might just as well pass it along to another backend.

This is how my setup looks like:

  • incoming get /foo
  • location match on /foo that passes to fcgi backend
  • fcgi backend analyzes request and returns response with
    x-accel-redirect /backend1/foo
  • location match on /backend1 passes the request along to http backend
  • backend responds with “final” request, master sends back to client

Johan Bergström wrote:

Hello,

On 16 jul 2010, at 09.33, Vincent Huang wrote:

Thanks for your help.
I need hold the response from one backend and send it to another(not
directory use the backed response as the result to client), so I have to
write some code inside nginx…
Thanks again;-)

The example might be a bit misleading in your case. What
X-Accel-Redirect does is take precedence over the location uri. You
don’t specifically have to pass the location match to a directory for
downloads, you might just as well pass it along to another backend.

This is how my setup looks like:

  • incoming get /foo
  • location match on /foo that passes to fcgi backend
  • fcgi backend analyzes request and returns response with
    x-accel-redirect /backend1/foo
  • location match on /backend1 passes the request along to http backend
  • backend responds with “final” request, master sends back to client

X-Accel-Redirect only works for intern redirect(just like what
ngx_http_subrequest(…)). My backend is another remote server(it should
like what ngx_http_upstream_t done in proxy/fcgi module).
Thanks for your help;-)

Regard,
Vincent

Johan Bergström wrote:

Hey,

Wouldn’t http://wiki.nginx.org/NginxXSendfile work for bouncing your
request between servers without modifying source code (thats how I do
it) ?

Cheers,
Johan

Thanks for your help.
I need hold the response from one backend and send it to another(not
directory use the backed response as the result to client), so I have to
write some code inside nginx…
Thanks again;-)

Regards,
Vincent

Hello!

On Fri, Jul 16, 2010 at 10:41:11AM +0200, Vincent Huang wrote:

  • location match on /backend1 passes the request along to http backend
  • backend responds with “final” request, master sends back to client

X-Accel-Redirect only works for intern redirect(just like what
ngx_http_subrequest(…)). My backend is another remote server(it should
like what ngx_http_upstream_t done in proxy/fcgi module).
Thanks for your help;-)

Yes, X-Accel-Redirect does internal redirect. No, internal
redirects isn’t limited to local files, they may be easily handled
by proxy/fastcgi modules as well. E.g. in configuration like
this:

location /back1 {
    proxy_pass http://back1;
}

location /back2
    proxy_pass http://back2;
}

backends may easily bounce request from one to another via
X-Accel-Redirect.

Maxim D.

Hi vincent,

Were you able to get to do what you wanted in comment #1?

I was wondering if you would happen to have some sample code or
pointers, that you wouldn’t mind sharing?

I have a similar requirement, and have asked about the same here:
http://www.ruby-forum.com/topic/3809975

Thanks,
Ashish

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs