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;
}
博客给出了一段Nginx配置代码,用于区分PC端、移动端、iOS平板端和安卓平板端的访问。通过对http_user_agent的匹配设置不同的标志位,根据不同设备类型将访问内容指向不同路径。还推荐了学习文章并给出转载来源。

被折叠的 条评论
为什么被折叠?



