Dictionary 内容类型匹配
我试图使用nginx映射模块来检测传入请求的内容类型是否为application/x-www-form-urlencoded。映射中的示例正则表达式代码不起作用。谁能看出我做错了什么?任何帮助都将不胜感激Dictionary 内容类型匹配,dictionary,Dictionary,我试图使用nginx映射模块来检测传入请求的内容类型是否为application/x-www-form-urlencoded。映射中的示例正则表达式代码不起作用。谁能看出我做错了什么?任何帮助都将不胜感激 map $content_type $ct { ~^/application\/x-www-form-urlencoded/ "application/x-www-form-urlencoded"; default "application/json"; } server {
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;
}
}
我最终没有使用map函数,而是:
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;
}
}