Nginx:仅当方法匹配时才定位



我正在尝试配置一个只与特定位置AND方法匹配的位置块。更确切地说:静态HTML用于所有位置,PHP用于单个POST位置。

  • 获取/->静态的
  • POST/->静态的
  • ANY/任何路径->静态的
  • ANY/特定->静态的
  • POST/特定->php

我可以突破位置块并进行下一场比赛吗?就像循环中的继续。

已经经历了很多,但甚至没有一种方法。这就是为什么这么奇怪的配置,因为后面是不同的应用程序。

您可以使用map区块链:

map $special_route$request_method $loc {
1POST      php;
default    static;
}
map $uri $special_route {
/specific  1;
# default value will be an empty string
}
server {
...
location / {
try_files /dev/null @$loc;
}
location @static {
# static location
...
}
location @php {
include fastcgi.conf;
# always use hard coded script filename for this specific POST request
fastcgi_param SCRIPT_FILENAME $document_root/path/to/your/script.php;
# pass the request to the FastCGI backend
fastcgi_pass unix:<socket_file_name>;
}
}

最新更新