nginx识别客户端是否为移动端

meilikeai0123    2022-08-19 09:25:57    6

nginx判断,通过请求头传递到php

        set $client "default";
        if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") {
            set $client "mobile";
        }

        location / {
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Host $host;
              proxy_http_version 1.1;
              proxy_set_header Connection "";
              proxy_set_header client $client; #重点

              if (!-f $request_filename){
                  proxy_pass http://webman1;
              }
          }