NGINX:不允许删除方法
NGINX : DELETE method not allowed
我正在使用 Nginx 来提供静态页面,但将请求传递给 API,我想处理 GET 和 DELETE 请求。
GET 工作正常,但 DELETE 请求被拒绝并显示“405:方法不允许”[=11=]
server {
listen 80;
server_name test.com;
root /var/test/cache/;
index index.php;
add_header 'Access-Control-Allow-Methods' 'GET, DELETE';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Origin';
add_header 'Access-Control-Allow-Origin' '*';
location ~* /questions {
...
try_files $url /index.php;
}
}
任何建议都会有帮助,谢谢。
解法:
修复 fastcgi_params 文件的问题,并改进位置规则条目:
server {
listen 80;
server_name test.com;
root /var/test/cache/;
index index.php;
location ~* /questions {
set_by_lua_block $url_format {
request_type = ngx.var.request_method
if request_type == 'DELETE' then
...
return url_format;
end
...
}
try_files $url_format /index.php;
}
}
我正在使用 Nginx 来提供静态页面,但将请求传递给 API,我想处理 GET 和 DELETE 请求。
GET 工作正常,但 DELETE 请求被拒绝并显示“405:方法不允许”[=11=]
server {
listen 80;
server_name test.com;
root /var/test/cache/;
index index.php;
add_header 'Access-Control-Allow-Methods' 'GET, DELETE';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Origin';
add_header 'Access-Control-Allow-Origin' '*';
location ~* /questions {
...
try_files $url /index.php;
}
}
任何建议都会有帮助,谢谢。
解法:
修复 fastcgi_params 文件的问题,并改进位置规则条目:
server {
listen 80;
server_name test.com;
root /var/test/cache/;
index index.php;
location ~* /questions {
set_by_lua_block $url_format {
request_type = ngx.var.request_method
if request_type == 'DELETE' then
...
return url_format;
end
...
}
try_files $url_format /index.php;
}
}