当前位置: > Linux服务器 > nginx >

nginx通过user-agent判断是否手机浏览器的方法

时间:2014-06-19 02:48来源:linux.it.net.cn 作者:IT网

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;


 

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容