我使用nginx为静态页面提供服务,但将请求传递给一个API,然后传递到Tornado应用程序,我希望处理GET、POST、PUT和DELETE请求。
GET和POST请求没有问题,但PUT和DELETE请求被拒绝,并显示"405: Method Not Allowed“
这个问题问的大致相同:How do I allow a PUT file request on Nginx server?,但答案没有解决我的问题,这让我认为这与我在设置中使用proxy_pass有关。
下面是我的nginx服务器配置:
upstream TornadoAPI {
server 127.0.0.1:8000;
}
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location /<<static url>>/ {
root /var/www;
index index.html;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /<<API url>>/ {
dav_methods PUT DELETE;
dav_access all:r;
proxy_pass http://TornadoAPI/api/;
}
}
我尝试过使用HttpDavModule指令(尽管我不认为我的应用程序符合HttpDav的要求--我无意让用户写文件)。我已经通过检查nginx -V确认了模块的存在。
下面是nginx access.log的输出示例:
<<IP address>> - - [06/Mar/2014:16:29:57 +0000] "PUT /<<API url>>/<<resource>> HTTP/1.1" 405 87 "<<ngix server root url>>" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"
有人能建议我还能做些什么来接受PUT和DELETE方法吗?
发布于 2018-04-30 09:22:56
您可以将此语句添加到配置文件中
dav_methods PUT DELETE MKCOL COPY MOVE;
具体详细参考nginx文档http://nginx.org/en/docs/http/ngx_http_dav_module.html
https://stackoverflow.com/questions/22231109
复制相似问题