我有两个静态内容包,分别名为" esc6“和" esc5”,用于支持esc6和esc5的浏览器。我应该如何编写nginx.conf文件,以便根据$http_user_agent值有条件地切换location指令。
Ex伪代码:
如果$http_user_agent包含"chrome || firefox || safari“,则esc6-bundle否则esc5-bundle
发布于 2019-06-27 20:13:47
您应该使用map指令。详情请参见this document。
例如:
map $http_user_agent $bundle {
default /js/esc5-bundle.js;
~*Chrome /js/esc6-bundle.js;
~*Firefox /js/esc6-bundle.js;
~*Safari /js/esc6-bundle.js;
}
server {
...
location = /js/bundle.js {
try_files $bundle =404;
}
...
}发布于 2019-06-27 20:01:46
在Nginx配置中尝试
location / {
if (($http_user_agent ~ "Chrome") || $http_user_agent ~ "firefox" ) || {
rewrite ^ esc6-bundle ;
}
rewrite ^ esc5-bundle ;
}希望它能帮上忙
https://stackoverflow.com/questions/56790049
复制相似问题