我正在尝试使用nginx map模块来检测传入请求的Content-Type是否为application / x-www-form-urlencoded。我在地图中的示例正则表达式代码无法正常工作。谁能发现我做错了什么?任何帮助将不胜感激。
map $content_type $ct {
~^/application\/x-www-form-urlencoded/ "application/x-www-form-urlencoded";
default "application/json";
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Content-Type $ct;
}
}
答案 0 :(得分:0)
我最终根本没有使用地图功能,而是:
server {
listen 80;
server_name www.example.com;
location / {
set $ct "application/json";
if ($content_type = "application/x-www-form-urlencoded") {
set $ct "application/x-www-form-urlencoded";
}
proxy_pass http://localhost:8000;
proxy_set_header Content-Type $ct;
}
}