Serve different files for specific user agents using nginx

If you have a new enough version of nginx (0.9.6+), you could accomplish this with a map:

map $http_user_agent $myindex {
  default /browser_index.html;
  ~iPhone /mobile_index.html;
}

server {
  listen 80;
  root /var/www;

  location = / { rewrite ^ $myindex; }
}

If you don't need an internal redirect (which you probably don't if you're just serving static files for the indexes), you could add a 'break' flag to the rewrite and avoid the internal redirect.

EDIT: If you're using an older version, you could do something like this:

server {
  listen 80;
  root /var/www;

  location = / {
    set $myindex /browser_index.html;
    if ($http_user_agent ~ iPhone) {
      set $myindex /mobile_index.html;
    }
    rewrite ^ $myindex;
  }
}

again, using the break flag if you don't need the internal redirect.