nginx user agent type detection

Calin Don calin at presslabs.com
Wed Oct 12 17:50:27 UTC 2011


I have assembled a way to detect user agent types by using ideas from:
http://notnotmobile.appspot.com/

This is the inital work I came up with:

map $http_user_agent $agent_type_phase1 {
        default 'mobile';
        '' 'unknown';
        ~*iphone|ipod|blackberry|palm|windows\s+ce 'mobile';
        ~*windows|linux|os\s+[x9]|solaris|bsd 'desktop';
        ~*spider|crawl|slurp|bot|feedburner 'bot';
}
map $http_x_skyfire_phone $agent_type_phase2 {
        default 'mobile';
        '' $agent_type_phase1;
}
map $http_x_operamini_phone_ua $agent_type {
        default 'mobile';
        '' $agent_type_phase2;
}

Please suggest any improvements. It is available also on
https://gist.github.com/1281950



More information about the nginx mailing list