Nginx Change Request from PUT to POST
Nginx only informs FastCGI of the request method via REQUEST_METHOD
param. So you may simply override the value and report anything you want to PHP. You'll have to declare another variable in your Nginx configuration, let's name it $fcgi_method
, based on the original request method:
map $request_method $fcgi_method { default $request_method; PUT POST;}
(note that map
sections should be at http
level, i.e. the same configuration level as server
blocks)
Then you may use it in your location like so:
fastcgi_param REQUEST_METHOD $fcgi_method;
It's important that this snippet is after typical include fastcgi_params
or alike.
I think it's worth pointing out in case anyone else considers this method for processing a PUT request in PHP (or any other request method that isn't populated into some global $_WHATEVER array to make life easy) that the correct way to get the body of a put request is to read the contents of php://input
.
Something like this should work:
$data = file_get_contents("php://input");