Forum: NGINX sending POSTs to backend

2974d09ac2541e892966b762aad84943?d=identicon&s=25 michelem (Guest)
on 2013-09-18 12:17
(Received via mailing list)
Hello folks,

I use nginx in front of a django/fastcgi application, and we serve a
subset
of the URLs of this webapp statically.

I use try_files to determine what's served statically and what goes to
the
backend.

Some of these URLs, however, contain forms and are at the same time
source
and targets for them. The former can be served statically, while the
latter
should hit the backend.

A simple "if ($request_method) { directive; }" would work, but I find no
effective "directive" to send the request to the backend.

Our basic setup looks like this:

server {
    root /site/static_files/;
    try_files $uri $uri/ $uri/index.html @appsrv;

    if ($request_method = POST) {
        # solution 1: try_files /var/emtpy/.foobar @appsrv
        # solution 2: fastcgi_pass 1.2.3.4:1234;
        # all of the above fail: directive not allowed here
        # solution 3: return 321; (+ define error_page 321 in server {})
        # I can't get the above handle correctly good and bad responses
from
the appsrv
    }

    location @appsrv {
        include /usr/local/etc/nginx/fastcgi_params_django;
        fastcgi_pass 1.2.3.4:1234;
    }
}

any suggestion to divert POST requests to the given named location?

cheers
michele

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,242944,242944#msg-242944
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-09-18 16:23
(Received via mailing list)
Hello!

On Wed, Sep 18, 2013 at 06:17:05AM -0400, michelem wrote:

> should hit the backend.
>     if ($request_method = POST) {
>         # solution 1: try_files /var/emtpy/.foobar @appsrv

This isn't going to work.

>         # solution 2: fastcgi_pass 1.2.3.4:1234;

This should work as long as you'll move the check into some
location.  It also might result in various problems in case of
more ifs added, see http://wiki.nginx.org/IfIsEvil.

Adding a "location /" is a good idea anyway.

>         # all of the above fail: directive not allowed here
>         # solution 3: return 321; (+ define error_page 321 in server {})
>         # I can't get the above handle correctly good and bad responses from
> the appsrv

You mean - other error_pages doesn't work for you then?  Try
recursive_error_pages, see here:

http://nginx.org/r/recursive_error_pages

>     }
>
>     location @appsrv {
>         include /usr/local/etc/nginx/fastcgi_params_django;
>         fastcgi_pass 1.2.3.4:1234;
>     }
> }
>
> any suggestion to divert POST requests to the given named location?

See above.  I would recommend "return + error_page" variant.

--
Maxim Dounin
http://nginx.org/en/donation.html
2974d09ac2541e892966b762aad84943?d=identicon&s=25 michelem (Guest)
on 2014-02-13 22:08
(Received via mailing list)
For the archives, I finally used the solution I document here:
http://forum.nginx.org/read.php?2,247532,247532#msg-247532

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,242944,247533#msg-247533
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.