Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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;
    fastcgi_pass   127.0.0.1:9000;
    include        fastcgi_params;
}
share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|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;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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