title: nginx: try_files's last value does not work when root is variable
body: <p>I have a Vue project which use "try_files" config to avoid 404 error when refreshing a "non root" url,like this:</p>
  
  <pre><code>location / {
      ......
      root /web/pcResource;
      try_files $uri $uri/ /index.html;
  }
  </code></pre>
  
  <p>It works fine. But when I need a variable "root" value before(decided by the user agent),like this:</p>
  
  <pre><code>set $dir "/web/pcResource";
  if ($http_user_agent ~* "(Android|iPhone|iPod|Symbian|BlackBerry|Windows Ph    one|Mobile|J2ME)") {
      set $dir "/web/mobileResource";
  }
  root   $dir;
  location / {
      ......
      try_files $uri $uri/ /index.html;
  }
  </code></pre>
  
  <p>The "/index.html" of try_files config always directs to the file in "/web/pcResource", so I get a 404 error when refreshing a "non root" url on the mobile browser.
  It seems that try_files only "remember" the first value of root. When I set $dir to "/web/mobileResource" first, then setted to "/web/pcResource" if user agent is pc, there is just a opposite error: I can refresh on my mobile browser and have a 404 error on pc browser.
  What is the correct config if I want to use a variable root value?</p>