Welcome! Log In Create A New Profile

Advanced

Re: Sub-request using Parent Request Body

agentzh
January 06, 2011 12:06AM
On Wed, Jan 5, 2011 at 8:20 AM, Roman Vasilyev <roman@anchorfree.com> wrote:
>
> Let me show one variant of nginx.conf's:
>  location / {
>    include proxy.conf;
>    eval_subrequest_in_memory off;
>    eval_override_content_type text/plain;
>    eval $res {
>      include spam_fastcgi.conf;
>      if ( $request_method = POST) {
>        fastcgi_pass   unix:/var/run/nginx/cgiwrap-dispatch.sock;
>      }
>    }
>   if ( $res = SPAM) {
>     rewrite ^ /terms-of-use.html redirect;
>   }
>  }

Please try the following:

location = /check-spam {
internal;

include spam_fastcgi.conf;
fastcgi_pass unix:/var/run/nginx/cgiwrap-dispatch.sock;
}

location / {
client_max_body_size 100k;
client_body_buffer_size 100k;

lua_need_request_body on;

rewrite_by_lua '
if ngx.var.request_method ~= "POST" then
return
end
local res = ngx.location.capture(
"/check-spam",
{ method = "POST", body = ngx.var.request_body }
)
if res.body == "SPAM" then
return ngx.redirect("/terms-of-use.html")
end
';

# ... your normal fastcgi_pass/proxy_pass/etc settings
# go here ...
}

Please note that you need the git HEAD of the "master" branch of the
ngx_lua git repos:

https://github.com/chaoslawful/lua-nginx-module

> I have some foreign spam analyzer which I'm running like fastcgi server
> written in perl.
> I tried to use $request_body as fastsgi_param arg, it was empty;
> Wrote module which creates $post_body var in rewrite stage and with echo
> $post_body it works, but on subrequest it gives empty body (I guess because
> it not passing POST into subrequest)
> maybe somebody have any ideas how to realize it other way, or may be how to
> get POST in subrequest?
>

If you have further issues, feel free to report here ;)

Happy nginx.conf hacking!
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Sub-request using Parent Request Body

Roman Vasilyev January 03, 2011 10:00PM

Re: Sub-request using Parent Request Body

agentzh January 03, 2011 10:22PM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 03, 2011 10:54PM

Re: Sub-request using Parent Request Body

agentzh January 04, 2011 01:28AM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 04, 2011 07:24PM

Re: Sub-request using Parent Request Body

agentzh January 06, 2011 12:06AM

Re: Sub-request using Parent Request Body

agentzh January 06, 2011 12:08AM

Re: Sub-request using Parent Request Body

agentzh January 06, 2011 12:16AM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 06, 2011 07:38PM

Re: Sub-request using Parent Request Body

Adrian Janeczek January 06, 2011 07:38PM

Re: Sub-request using Parent Request Body

agentzh January 07, 2011 01:40AM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 07, 2011 03:18PM

Re: Sub-request using Parent Request Body

agentzh January 08, 2011 02:26AM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 10, 2011 02:42PM

Re: Sub-request using Parent Request Body

Roman Vasilyev January 10, 2011 03:36PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 84
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready