方法一、Rewrite
server {
listen 80;
server_name h5-test.pbsedu.com;
location / {
root html;
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
rewrite ^/(.*)$ http://wwwh5-dev.pbsedu.com/$1 permanent; #进行正常访问的时候判断user_agent为手机,则重写至此页面
}
index index.html index.htm;
}
方法二、直接区分
server {
listen 80;
server_name h5-test.pbsedu.com;
location / {
root html;
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
root mobile #需要在html同级目录下建立mobile文件夹,存放手机端访问内容
}
index index.html index.htm;
}