---
title: "NGINX: 405 Not Allowed"
author: "stephen830"
date: "2015-09-14T08:57:25Z"
tags: []
categories: ["开源软件"]
slug: "nginx-405-not-allowed"
draft: false
lastmod: "2015-09-14T08:57:25Z"
id: 2243133
url: "https://stephen830.iteye.com/blog/2243133"
---

NGINX: 405 Not Allowed

今天碰到一个dz的批量上传文件不成功的问题。  
追踪发现，是把静态文件都优化了新地址导致的，用图片服务器存放了swf文件  
swf文件上传文件时，就变成向静态文件做post，nginx就会返回405错误  
修正域名即可解决。

另外，发现一个好玩的：

NGINX不允许向静态文件提交POST方式的请求，否则报405错误。测试方法为，使用curl向服务器上的静态文件提交POST请求：  
curl -d 1=1 http://localhost/version.txt

得到以下结果：

&lt;html&gt;  
&lt;head&gt;&lt;title&gt;405 Not Allowed&lt;/title&gt;&lt;/head&gt;  
&lt;body bgcolor="white"&gt;  
&lt;center&gt;&lt;h1&gt;405 Not Allowed&lt;/h1&gt;&lt;/center&gt;  
&lt;hr&gt;&lt;center&gt;nginx/1.0.11&lt;/center&gt;  
&lt;/body&gt;  
&lt;/html&gt;

网上传抄的添加以下配置的解决办法不可用：

error\_page 405 =200 @405;  
location @405  
{  
    root /srv/http;  
}

一种不完美但可用的方法为：  
upstream static\_backend {  
    server localhost:80;  
}

server {  
    listen 80;

    # ...

    error\_page 405 =200 @405;  
    location @405 {  
        root /srv/http;  
        proxy\_method GET;  
        proxy\_pass http://static\_backend;  
    }  
}

即转换静态文件接收的POST请求到GET方式。

http://0x3f.org/blog/nginx...