使用 Nginx 内置 $http_user_agent 来区分( 电脑 pc、手机 mobile、平板 pad )端的内容访问...

location / {
#pc端内容访问
set $flag "pc";
set $num 1;
set $hua "${http_user_agent}";
set $iospad "${http_user_agent}";
set $androidpad "${http_user_agent}";

#mobile端访问内容
if ( $http_user_agent ~* "Mobile") {
      set $flag "mobile";
}

#ios-pad端访问内容
if ( $iospad ~* "iPad|ipad") {
      set $flag "pad";
}

#android-pad端访问内容
if ( $androidpad ~* "Android") {
      set $num "${num}2";
}

if ( $hua !~* "Mobile") {
    set $num "${num}3";
}

if ( $num = "123") {
     set $flag "pad";
}

root /usr/local/etc/nginx/website/$flag;

index index.html index.htm;
}

推荐学习文章:https://yq.aliyun.com/articles/44957

转载于:https://www.cnblogs.com/Kummy/p/6232018.html

猜你喜欢

转载自blog.csdn.net/weixin_33712987/article/details/93428471