我们有一个在Windows服务器上运行的repo服务器,它提供一些静态文件,这些静态文件应该由我们的工作者节点使用Python-urllib抓取。 问题在于,当我们向使用Python存在的文件发出请求时,我们会收到一个404错误,但是,如果我直接从浏览器访问文件,使用Python-urllib正在使用的相同链接,它工作得很好,文件被下载。 示例访问日志:
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"
我在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"
从这些日志看来确实正在生成一个405,而不是404,但是Python显示了一个404页面。 请注意,如果我们通过htdocs / html文件夹传输,这是一个新的下载的nginx下相同的目录结构在Apache下工作。
没有对Nginx进行configuration更改
你不能在POST请求中使用nginx的静态资源,就是这样。
但是你可以通过使用error_page指令来做一些技巧:
error_page 405 =200 $request_uri;
404错误页面是因为nginx没有find405错误页面,你可以从nginx错误日志中看到。 所以真正的错误是错误的请求,并且返回错误405。
检查HTTP错误代码,你可以看到405是“方法不允许”:
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.
所以你可能是用错误的方式使用Python-urllib ……最可能的是你使用了错误的POST方法。 你有x-www-form-urlencoded (即:POST数据在url中)和Multipart / form-data (即:POST数据在上传的文件中)。
所以重新检查你如何做POST请求。