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

We have a repo server running on a Windows box serving some static files that are supposed to be grabbed by our worker nodes using Python-urllib. The problem lies in the fact that when we make a request to a file that we know exists using Python we receive a 404 error, however, if I access the file directly from my browser, using the same link that Python-urllib is using, it works perfectly fine, and the file is downloaded. Example access log:

xxx.xxx.xxx.xxx - - [24/Jul/2013:17:15:53 -0400] "POST /x/dl/Bukkit_Beta.jar.conf HTTP/1.1" 405 172 "-" "Python-urllib/2.7"

I did notice something weird in error.log:

2013/08/04 22:29:11 [error] 6456#2696: *807 CreateFile() "C:\Users\Administrator\Desktop\Nginx/html/MCProHosting/dl/405" failed (2: The system cannot find the file specified), client: 198.15.64.226, server: localhost, request: "GET /MCProHosting/dl/405 HTTP/1.1", host: "repo.mcprohosting.com"

It does appear that from these logs a 405 is being generated, rather than a 404, but Python shows a 404 page. Please note that this is a fresh download of nginx the same directory structure works under Apache if we transfer over the htdocs/html folder.

No configuration changes have been made to Nginx

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You can't make POST requests to static resources in nginx, that's it.

But you can do some trick by using the error_page directive:

error_page 405 =200 $request_uri;
share|improve this answer
add comment

The 404 error page is because nginx don't find the 405 error page, as you can see from the nginx error log. So the real error is the request that is bad and it's returning error 405.

Checking the HTTP error code you can see that 405 is "Method Not Allowed":

10.4.6 405 Method Not Allowed
 The method specified in the Request-Line is not allowed for the resource identified
 by the Request-URI. The response MUST include an Allow header containing a list of 
 valid methods for the requested resource.

So you are probably using the Python-urllib in the wrong way... most probably you are using the wrong POST method. You have x-www-form-urlencoded (ie: POST data is in the url) and Multipart/form-data (ie: POST data in in a uploaded file).

So recheck how are you doing the POST request.

share|improve this answer
    
I do not actually have access to the code behind it, the big thing to note here is that it works perfectly fine under Apache, why would it suddenly stop working with Nginx? –  Matthew Salsamendi Aug 5 '13 at 8:09
add comment

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.