使用 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}";html

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

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

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

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

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

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

index index.html index.htm;
}htm

 

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

相关文章
相关标签/搜索