views:

461

answers:

2

Hello. I wrote a high-performance HTTP event server in C++ and I want to make it work flawlessly with nginx and PHP-FPM (fastcgi). This is a snippet of my nginx configuration.

    location ~ \.eve$ {
        gzip off;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://127.0.0.1:9001;
        proxy_intercept_errors on;
        error_page 505 = @fallback // this is actually BACKEND.php
    }

My event server returns 505 errors if there IS an event, otherwise it hangs, and eventually returns a "NO STATE CHANGE" directive that I handle with JS or what have you (this is basically comet). The point is that I would like nginx to catch the 505 error and forward that request to PHP so PHP can handle the event accordingly. My server is basically just an event hub, allowing many many users to be able to connect and see if there are any new events. If there IS an event, PHP handles the event distribution, including permissions and other volatile stuff.

The problem is that nginx isn't passing the POST (or GET) variables that were passed to *.eve, to BACKEND.php. Now I presume this is by design (due to the error_page directive), but I figured that there must be some way of making it work. My server runs on 9001, PHP-FPM runs on 9000. Any ideas?

A: 

Your server can return a response with X-Accel-Redirect header pointing a backend url. In this case nginx will make the request to the url and return the response back to the user. No 30[12] redirects, just as if user requested the url in the first place.

http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/
Google for other examples.

This is nginx specific, but the idea is featured in lighttpd with X-Sendfile header.

I would not count on POST request parameters passing here. Mirror POST parameters in GET ones of X-Accel-Redirect return, if your backend can accept that. error_page won't pass any indeed.

rzab
+1  A: 

I fixed the problem by simply rebuilding the most recent version of nginx. The config, as well as the POST and GET forwarding works perfectly. Weirdness.

David Titarenco
There are 58257 "unanswered questions" in StackOverflow. Please help lower that number by accepting your own answer in this case (since you solved the problem yourself).
Nicolás