سؤال

We have an NginX balancing proxy in front of our web application. Unfortunately there is not enough development resources to support outdated browsers, yet :( We want to redirect members of our web project to /outdated page by their browser user-agent data like this (https://www.in2circle.com/outdated). For some reason we don't want to load back-end with User-Agent content analysis logic. I've heard it's easy to do with NginX http://nginx.org/en/docs/http/ngx_http_map_module.html If somebody did so, can you help me with examples and explanations, please!

هل كانت مفيدة؟

المحلول

Maybe someone will find this helpful. Next solution works pretty good and is exactly what I wanted:

map $http_user_agent $outdated {
    default                                 0;
    "~MSIE [1-9]\."                         1;
    "~Mozilla.*Firefox/[1-9]\."             1;
    "~Mozilla.*Firefox/[0-2][0-9]\."        1;
    "~Mozilla.*Firefox/3[0-1]\."            1;
    "~Opera.*Version/[0-9]\."               1;
    "~Opera.*Version/[0-1][0-9]\."          1;
    "~Opera.*Version/2[0-1]\."              1;
    "~AppleWebKit.*Version/[0-6]\..*Safari" 1;
    "~Chrome/[0-9]\."                       1;
    "~Chrome/[0-2][0-9]\."                  1;
    "~Chrome/3[0-3]\."                      1;
}

if ($outdated = 1){
    rewrite ^ /outdated redirect;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top