上传文件时不允许NGINX 405

时间:2017-10-05 14:15:39

标签: curl nginx

我需要将所有文件上传请求https://example.com/year2017/monthsept/upload/重定向到https://example.com/upload/

在nginx配置中,我在服务器块中有以下位置/重写规则。但是,我收到405错误。

location ~ ^/year2017/monthsept/upload/(.*) {
rewrite ^year2017/monthsept/upload/$1 /upload/$1 permanent;
}

$ curl --verbose --upload-file test.txt https://example.com/year2017/monthsept/upload/
  

PUT /ye2017/monthsept/upload/test.txt HTTP / 1.1   < HTTP / 1.1 405不允许   *发送结束前发生HTTP错误,停止发送   *关闭连接0

我经常更新重写规则,但没有快乐。

正确的nginx规则是什么?

1 个答案:

答案 0 :(得分:0)

您永远不会重写POST或PUT请求。因为这会将请求更改为GET请求。应始终按原样处理POST / PUT请求。因此,您只需使用正确的路径将其代理回nginx

location ~ ^/year2017/monthsept/upload/(.*) {
    proxy_pass http://127.0.0.1/upload/$1;
}
相关问题