title: Multiple Laravel Projects on a single domain with NGINX
body: <p>At work we have a single staging server with a staging domain, something like <a href="https://staging.example.com" rel="nofollow noreferrer">https://staging.example.com</a>. We recently decided to switch from Apache to NGINX on a new server and we're having issues with our Laravel routing.</p>
  
  <p>All of our laravel apps sit in sub-directories on the staging server, like so.</p>
  
  <ul>
  <li><a href="https://staging.example.com/app1/public" rel="nofollow noreferrer">https://staging.example.com/app1/public</a></li>
  <li><a href="https://staging.example.com/app2/public" rel="nofollow noreferrer">https://staging.example.com/app2/public</a></li>
  </ul>
  
  <p>I've tried configuring the NGINX conf file as specified in the <a href="https://laravel.com/docs/master#web-server-configuration" rel="nofollow noreferrer">Laravel docs</a> but get a 404 when accessing any 2nd level route, i.e. <a href="https://staging.example.com/app1/public/a/b" rel="nofollow noreferrer">https://staging.example.com/app1/public/a/b</a></p>
  
  <p>Using something like the below config, I can access all the routes in an app.</p>
  
  <pre><code>location @laravel {
          rewrite /app1/public/(.*)$ /app1/public/index.php?$1;
  }
  
  location / {
          try_files $uri $uri/ @laravel;
  }
  </code></pre>
  
  <p>However, we have many apps hosted on this server and we don't want to have to update an NGINX conf file every time we want to add an app to the server.</p>
  
  <p>Is there a way of constructing a rewrite to apply to any sub-directory and keep Laravel's routing system working?</p>
  
  <p>Note: I've also tried this rewrite <code>rewrite (.*)/(.*)$ $1/index.php?$2</code> and that doesn't work for 2nd level routes.</p>