nginx通过user-agent判断是否手机浏览器的方法,这在检测通过手机浏览pc页面然后跳转到手机页面时很有用。
user-agent相关知识:
http://www.developershome.com/wap/detection/detection.asp?page=userAgentHeader
http://search.cpan.org/~cmanley/Mobile-UserAgent-1.05/lib/Mobile/UserAgent.pm
http://www.zytrax.com/tech/web/mobile_ids.html
http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
nginx配置实例:
location = / {
root /var/www/path;
if ($http_user_agent ~* "Nokia") { rewrite . /index.html break; }
if ($http_user_agent ~* "Mobile") { rewrite . /index.html break; }
if ($http_user_agent ~* "SAMSUNG") { rewrite . /index.html break; } }
if ($http_user_agent ~* "SonyEricsson") { rewrite . /index.html break; }
if ($http_user_agent ~* "MOT") { rewrite . /index.html break; } }
if ($http_user_agent ~* "BlackBerry") { rewrite . /index.html break; }
if ($http_user_agent ~* "LG") { rewrite . /index.html break; } }
if ($http_user_agent ~* "HTC") { rewrite . /index.html break; }
if ($http_user_agent ~* "J2ME") { rewrite . /index.html break; }
if ($http_user_agent ~* "Opera Mini") { rewrite . /index.html break; } }
index index.html;
}