Welcome! Log In Create A New Profile

Advanced

Different locations based on $request_method

Aaron Starr
December 02, 2010 04:02PM
Hello, all,

I would like to configure nginx to return a file if the request method is
GET. But, if the request method is PUT or POST, I'd like for the back end to
handle it. So, ideally, something like this:

location / GET {
try_files $uri $uri/index.html $uri.html @missing;
}

location / PUT {
proxy_pass http://sinatra;
....
}

location @missing {
return 404;
}

I understand that that particular syntax isn't possible. Is something like
this the best way to do it?

location / {

if ($request_method = PUT) {
proxy_pass http://sinatra;
....
break;
}

try_files $uri $uri/index.html $uri.html @missing;
}

location @missing {
return 404;
}

I'm aware that if==bad, but not sure if there's a better way to redirect
traffic based on the request method?

Thanks for any help,

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

Different locations based on $request_method

Aaron Starr December 02, 2010 04:02PM

Re: Different locations based on $request_method

Aaron Starr December 03, 2010 04:48PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 154
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