title: Nginx multiple locations with different roots
body: <p>I have really simple nginx configuration with 3 locations inside. Each of them have it's own root directory + I should be able to add another in the future easily.</p>
  
  <p><strong>What I want:</strong></p>
  
  <p>Request <code>/admin</code> => location <code>^/admin(/|$)</code></p>
  
  <p>Request <code>/admin/</code> => location <code>^/admin(/|$)</code></p>
  
  <p>Request <code>/admin/blabla</code> => location <code>^/admin(/|$)</code></p>
  
  <p>Request <code>/client</code> => location <code>^/client(/|$)</code></p>
  
  <p>Request <code>/client/</code> => location <code>^/client(/|$)</code></p>
  
  <p>Request <code>/client/blabla</code> => location <code>^/client(/|$)</code></p>
  
  <p>Request <code>/blabla</code> => location <code>/</code></p>
  
  <p>Request <code>/admin-blabla</code> => location <code>/</code></p>
  
  <p>Request <code>/client-blabla</code> => location <code>/</code></p>
  
  <p><strong>Actual result:</strong></p>
  
  <p>All requests goes to location <code>/</code>.</p>
  
  <p>I tried many different suggestions from docs, stackoverflow and other sources using different combinations of aliases, try_files, roots and regexes, but nothing worked for me.</p>
  
  <p>Only when I tried to use just <code>return 200 'admin';</code> and <code>return 200 'front'</code> it worked as intended.</p>
  
  <p><strong>Minimal config:</strong></p>
  
  <pre><code>server {
      listen 80;
      index index.html;
  
      location / {
          root /var/www/html/www_new/front;
          try_files $uri $uri/ /index.html;
      }
  
      location ~ ^/admin(/|$) {
          root /var/www/html/www_new/admin;
          try_files $uri $uri/ /index.html;
      }
  
      location ~ ^/client(/|$) {
          root /var/www/html/www_new/client;
          try_files $uri $uri/ /index.html;
      }
  }
  </code></pre>
  
  <p><strong>Directory structure:</strong></p>
  
  <ul>
  <li>/admin</li>
  <li>/client</li>
  <li>/front</li>
  </ul>
  
  <p>Thank you</p>