nginx的location判断用户端是手机还是pc端配置

Love The Way You Lie 2022-12-10 03:35 459阅读 0赞

配置

  1. # 判断 pc 和 mobile 的 H5
  2. location / {
  3. set $is_mobile false; #设置一个初始值
  4. if ( $http_cookie ~* "ACCESS_TERMINAL=mobile" ) { #判断匹配手机端
  5. set $is_mobile true;
  6. }
  7. if ($http_user_agent ~* (android|ip(ad|hone|od)|kindle|blackberry|windows\s(ce|phone))) { #匹配手机端类型
  8. set $is_mobile true;
  9. }
  10. if ($is_mobile = true) {
  11. root /usr/local/openresty/nginx/html/mobile/;
  12. break;
  13. }
  14. root /usr/local/openresty/nginx/html/pc/;

发表评论

表情:
评论列表 (有 0 条评论,459人围观)

还没有评论,来说两句吧...

相关阅读

    相关 判断手机PC代码

    那天做到一个需要判断是手机端还是PC端的功能。我也不太懂,自己不会写,就在网上找了一下。 找到的答案也是有的五花八门,最后看到一个比较简洁的就试用了一下,没得问题就继续用着了