You can modify cache key to include user-agent. For example:
fastcgi_cache_key “$scheme$request_method$host$request_uri$rt_session$http_user_agent”;
Above might be very inefficient so its better to do something like below:
set $rt_mobile "no";
if ($http_user_agent ~* '(iPhone|iPod|android|blackberry)') {
set $rt_mobile "yes";
}
fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session$rt_mobile";
Above will create 2 version of every page - one for mobiles and other for non-mobile devices.
You can tweak line if ($http_user_agent ~* ‘(iPhone|iPod|android|blackberry)’)
to add/remove desired mobile agents to the list.
But our recommended way of servicing mobile site is using responsive themes - https://rtcamp.com/responsive-web-design/