2017-10-05 836 views
0

时不允许我需要重定向所有文件上传请求https://example.com/year2017/monthsept/upload/https://example.com/upload/NGINX 405上传文件

在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 /year2017/monthsept/upload/test.txt HTTP/1.1 < HTTP/1.1 405不允许 * HTTP错误发送的结束之前,停止发送 *关闭连接0

我已经更新了重写规则,所以经常但没有喜悦。

正确的nginx规则是什么?

回答

0

您永远不会重写POST或PUT请求。因为这会将请求更改为GET请求。一个POST/PUT请求应该总是作为它处理。所以,你只是代理回用正确的路径

location ~ ^/year2017/monthsept/upload/(.*) { 
    proxy_pass http://127.0.0.1/upload/$1; 
} 
+0

嗨塔伦, 此时nginx的,我要补充的nginx的是2个上游服务器负载平衡器。额外的proxy_pass如何处理负载均衡?删除这样的IP地址? location〜^/year2017/monthsept/upload /(.*){ proxy_pass/upload/$ 1; } – Mark

+0

是的,这应该工作太 –

+0

这有助于我现在有工作作为使用 '位置〜^/year2017/monthsept /上传/(.*){ proxy_pass example.com/upload/$1预期; }' – Mark