Need help calling PHP as a fallback

I wrote a very scalable HTTP event server in C++ and I would like to
make it work with nginx.
My server is on port 9001, PHP-FPM is running on port 9000.

My server is set up to return a 504 error when an event is found, and
the 504 error should trigger the PHP backend.
I’ve been trying to figure out a way to make it work with nginx and it’s
something so elementary, I think I’m just being really stupid… so I
need some help.

This is basically a short rundown of what happens.
A client hits something like myhost.com/event/, and hangs until there is
an event to server, expiring after 30 seconds by default (if it expires,
my server returns a “NO EVENT” reply, which works); however, if there IS
an event, my server is set up to kick off the client, triggering a 504.
Somehow I want to catch that 504, and redirect the client to a PHP
backend (with the query intact).

This is what I have so far. I haven’t worked much with nginx so bear
with me…

    location /event/ {
        proxy_pass http://localhost:9001/callback.eve;
        proxy_intercept_errors on;
        error_page 504 = @fallback; #if I straight up put 

backend.php here, the POST/GET variables disappear
}

    location @fallback {
        internal;
        fastcgi_param SCRIPT_FILENAME $document_root/backend.php;
        fastcgi_param  QUERY_STRING     $query_string;
        include fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
    }

I get some really strange results with the aforementioned config… nginx
doesn’t break, I don’t get an error or anything. PHP doesn’t break
either. All I get is a blank page (as in, totally blank) with a 200 OK
code. I’m really confused here, and I’m almost certain there has to be
an easy way of doing this

Posted at Nginx Forum:

Is proxy_pass supposed to call something with a .eve extension?

On Jan 4, 2010 11:50 PM, “davvv” [email protected] wrote:

I wrote a very scalable HTTP event server in C++ and I would like to
make it
work with nginx.
My server is on port 9001, PHP-FPM is running on port 9000.

My server is set up to return a 504 error when an event is found, and
the
504 error should trigger the PHP backend.
I’ve been trying to figure out a way to make it work with nginx and it’s
something so elementary, I think I’m just being really stupid… so I
need
some help.

This is basically a short rundown of what happens.
A client hits something like myhost.com/event/, and hangs until there is
an
event to server, expiring after 30 seconds by default (if it expires, my
server returns a “NO EVENT” reply, which works); however, if there IS an
event, my server is set up to kick off the client, triggering a 504.
Somehow
I want to catch that 504, and redirect the client to a PHP backend (with
the
query intact).

This is what I have so far. I haven’t worked much with nginx so bear
with
me…

   location /event/ {
       proxy_pass http://localhost:9001/callback.eve;
       proxy_intercept_errors on;
       error_page 504 = @fallback; #if I straight up put backend.php

here, the POST/GET variables disappear
}

   location @fallback {
       internal;
       fastcgi_param SCRIPT_FILENAME $document_root/backend.php;
       fastcgi_param  QUERY_STRING     $query_string;
       include fastcgi_params;
       fastcgi_pass  127.0.0.1:9000;
   }

I get some really strange results with the aforementioned config… nginx
doesn’t break, I don’t get an error or anything. PHP doesn’t break
either.
All I get is a blank page (as in, totally blank) with a 200 OK code. I’m
really confused here, and I’m almost certain there has to be an easy way
of
doing this

Posted at Nginx Forum:

Yes, callback.eve is the correct resource

Posted at Nginx Forum:

.eve is not technically an extension, it’s just a resource flag I
allocated in my C++ server (I plan to expand it later on). But either
way, I’m pretty sure that part isn’t the issue. It’s just that I’m not
sure how to redirect the FULL request as if it were fresh from the
client AFTER an error has been served by my server (or proxy, or
whatever you want to call it).

Posted at Nginx Forum:

Just making sure! Don’t have experience with that extension.

On Jan 5, 2010 12:39 AM, “davvv” [email protected] wrote:

Yes, callback.eve is the correct resource

Posted at Nginx Forum:

_______________________________________________ nginx mailing list
[email protected] http://nginx.or

Just create debug log and check what happens behind the scenes…

In order to do that, you’ll need to build nginx with --with-debug
parameter
and set error_log to debug level in configuration.

Best regards,
Piotr S. < [email protected] >

Thanks for the advice Piotr, but instead of helping me, it just
complicated the situation a whole lot more :stuck_out_tongue:

2010/01/05 01:22:28 4020#0: signal 17 (SIGCHLD) received
2010/01/05 01:22:28 4020#0: worker process 4024 exited on signal 11
2010/01/05 01:22:28 4020#0: start worker process 9274
2010/01/05 01:22:28 4020#0: signal 29 (SIGIO) received
2010/01/05 01:22:29 4020#0: signal 17 (SIGCHLD) received
2010/01/05 01:22:29 4020#0: worker process 5209 exited on signal 11
2010/01/05 01:22:29 4020#0: start worker process 9294
2010/01/05 01:22:29 4020#0: signal 29 (SIGIO) received
2010/01/05 01:22:31 4020#0: signal 17 (SIGCHLD) received
2010/01/05 01:22:31 4020#0: worker process 5171 exited on signal 11
2010/01/05 01:22:31 4020#0: start worker process 9321
2010/01/05 01:22:31 4020#0: signal 29 (SIGIO) received
2010/01/05 01:22:32 4020#0: signal 17 (SIGCHLD) received

Looks like nginx is segfaulting… any ideas of what could be causing
this?

Something to do with:

location @fallback {
internal;
fastcgi_param SCRIPT_FILENAME $document_root/backend.php;
fastcgi_param QUERY_STRING $query_string;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}

I would assume…

Posted at Nginx Forum:

Looks like nginx is segfaulting… any ideas of what could be causing this?

…it should be somewhere in the debug log :stuck_out_tongue:

Best regards,
Piotr S. < [email protected] >

Oops, sorry about that; I thought you meant to simply add “debug” to the
log directive in the .conf.

But! I updated to 0.8.31 and rebuilt with --with-debug (as per your
recommendation) and everything works perfectly.

Here’s my final nginx.conf if anyone else will want to do something
similar in the future.

    location /eve/ {
        proxy_pass http://127.0.0.1:9001;
        proxy_intercept_errors on;
        error_page 504 = @fallback;
    }

    location @fallback {
          rewrite  ^(.*)$  /backend.php;
    }

Kind of a messy rewrite, but for my purposes, it’s fine. Thanks for all
the help, and happy 2010 =)

Posted at Nginx Forum:

On Tue, Jan 5, 2010 at 3:15 PM, davvv [email protected] wrote:

    }

    location @fallback {
       rewrite  ^(.*)$  /backend.php;
    }

Kind of a messy rewrite, but for my purposes, it’s fine. Thanks for all the help, and happy 2010 =)

Posted at Nginx Forum: Re: need help calling PHP as a fallback

I believe you can just do this

   location /eve/ {
       proxy_pass http://127.0.0.1:9001;
       proxy_intercept_errors on;
       error_page 504 = /backend.php;
   }


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Doubt this is the issue but you don’t need internal in the named
location. All named locations are internal already.

Sent from my iPhone