I am trying to figure out how to allow PUT to a static file in nginx, the put request will be proxied to a php script. An example of the request I am trying to get working using curl is:

curl -X PUT  -d "tags=abc,def" cp.local/api/Image/myimage.jpg

This throws a 405 Not Allowed in nginx. Other urls work, for example:

curl -X PUT  -d "tags=abc,def" cp.local/api/Image/myimage.pdf

I read a forum thread where someone had a similar problem but with POST but it is outdated and there didn't seem to be a real fix in the thread.

The relevant nginx config directive is:

location ~* ^/api/.*$ {
    root           /my/path/public;
    fastcgi_param  SCRIPT_FILENAME  /my/path/public/Api.php;
    include        fastcgi_params;

You cannot do anything but GET a static file. If you want to POST, PUT, DELETE etc you need to make sure your have a location block handling the URI and that this location block handles the request in a way that allows such requests.

For instance by proxy_passing to Apache or fastcgi_passing to PHP.

With the config you have provided it should theoretically be allowed. But you've removed a lot of information and most likely you have a location block to catch static files. When you're dealing with regex locations the first matching one will be used so you need to make sure your api location is defined before any other matching locations.

| improve this answer | |
  • Good catch on having another location block catching the static files. That was the issue. – MitMaro May 18 '11 at 21:07

Intercept HTTP status 405 and process the request with your script:

error_page 405 = /api/Api.php;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.