nginx根据ua判断是否允许访问

在nginx中$http_user_agent就是ua,可以在nginx配置文件中根据ua做判断

下面这个例子就是,是gif、jpg、jpeg、png、mp4、mp3格式的资源的话,如果ua不匹配UNI-APP或者Electron就禁止访问,返回404

location ~ .*\.(gif|jpg|jpeg|png|mp4|mp3)$
    {
      if ( $http_user_agent !~ "(UNI-APP)|(uni-app)|(Electron)" ){
          return 404;
      }
    }

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: