只允许get/post请求

1
2
3
4
5
6
7
8
9
if ($request_method !~* GET|POST)
{
    return 403;
}
#或者
if ($request_method !~ ^(GET|POST)$)
{
    return 403;
}

拒绝PUT、DELETE、POST请求

1
2
3
4
5
6
7
8
9
if ($request_method = PUT){
    return 403;
}
if ($request_method = DELETE){
    return 403;
}
if ($request_method = POST){
    return 403;
}
  • 注意:if和(之间要有一个空格,否则会报错。要放在server层里面。
1
2
3
server{
   #放这里
}