Nginx allow post requests from a certain server
http {
geo $allowed_post_put {
default 0;
127.0.0.1 1;
::1 1;
}
map $request_method:$allowed_post_put $return_405 {
"POST:0" 1;
"PUT:0" 1;
}
}
location / {
if ( $return_405 = 1 ) {
return 405;
}
}
http://nginx.org/en/docs/http/ngx_http_geo_module.html - geo module allows to create variables depending on client IP address.
http://nginx.org/en/docs/http/ngx_http_map_module.html - map module creates variables whose values depend on values of other variables.
if
directive from rewrite module does not allow complex logical expressions, just single variable comparsion. So we use map module to create variable that depends both on client IP and request method.
UPD: An alike configuration with geo/map/if hack works fine for me in production.