# Nginx user agent type detection

**URL:** <https://www.ruby-forum.com/t/nginx-user-agent-type-detection/212754>\
**Category:** NGINX\
**Created:** [October 12, 2011, 7:50pm UTC](https://www.ruby-forum.com/t/nginx-user-agent-type-detection/212754 "2011-10-12T19:50:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 12, 2011, 7:50pm UTC](https://www.ruby-forum.com/t/nginx-user-agent-type-detection/212754/1 "2011-10-12T19:50:59Z")

</div>

I have assembled a way to detect user agent types by using ideas from:  
[http://notnotmobile.appspot.com/](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/calind/1281950>

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [October 12, 2011, 9:18pm UTC](https://www.ruby-forum.com/t/nginx-user-agent-type-detection/212754/2 "2011-10-12T21:18:51Z")

</div>

I did it in lua bcs I had slightly more complex rules. Looks like what  
you  
have will work, it’s just O(n)

---

<div class="post-metadata">

**Author:** ![Calin\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@Calin\_D](https://www.ruby-forum.com/u/Calin_D)\
**Post date:** [October 12, 2011, 9:25pm UTC](https://www.ruby-forum.com/t/nginx-user-agent-type-detection/212754/3 "2011-10-12T21:25:03Z")

</div>

On 12 October 2011 22:17, Brian A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I did it in lua …  
> Care to share?
