title: Nginx alias breaks due to try_files $uri alias bug
body: <p>I have a versioned Symfony API instance that I want to configure in the following manner:</p>
  <ul>
  <li>api.com/api/v1 <strong>-&gt;</strong> /srv/api-v1/public/index.php</li>
  <li>api.com/api/v2 <strong>-&gt;</strong> /srv/api-v2/public/index.php</li>
  </ul>
  <p>I've tried to approach this using nginx location and aliases, as it's Symfony we use try_files (<a href="https://symfony.com/doc/current/setup/web_server_configuration.html#nginx" rel="nofollow noreferrer">as recommended</a>) to check for an actual file prior to defaulting to <code>index.php</code>.</p>
  <h1>Problem</h1>
  <p>It seems there is a <a href="https://trac.nginx.org/nginx/ticket/97" rel="nofollow noreferrer">known nginx bug</a> that breaks the <code>$uri</code> variable with an <code>alias</code> and <code>try_files</code>.</p>
  <p>How can I get around this bug to achieve my desired outcome?</p>
  <p><strong>nginx conf</strong></p>
  <pre><code>server {
      listen 443 http2;
      listen [::]:443 http2;
      server_name api.com;
      root /srv/default/public/; # default root when no version
   
      location /api/v1 {
          alias /srv/api-v1/public/;
          try_files $uri /index.php$is_args$args;
      }
  
      location /api/v2 {
          alias /srv/api-v2/public/;
          try_files $uri /index.php$is_args$args;
      }
  
      location ~ ^/index\.php(/|$) {
          include /etc/nginx/fastcgi.conf;
          fastcgi_pass unix:/run/php-fpm-php7.2.socket;
          fastcgi_split_path_info ^(.+?\.php)(/.*)$;
          internal;
          fastcgi_read_timeout 300;
      }
  }
  </code></pre>
  <h1>Attempted fix</h1>
  <p>Going by <a href="https://stackoverflow.com/a/45642689/1072492">this hacky fix</a> I have created the following which does work but generates a huge config file, not ideal:</p>
  <pre><code>upstream v1 {
      server 127.0.0.1;
  }
  upstream v2 {
      server 127.0.0.1;
  }
  server {
      listen 443 http2;
      listen [::]:443 http2;
      server_name api.com;
   
      location /api/v1 {
          proxy_pass http://v1;
      }
  
      location /api/v2 {
          proxy_pass http://v2;
      }
  }
  server {
      server_name v1;
      root /srv/api-v1/public/;
  
      location / {
          try_files $uri /index.php$is_args$args;
      }
  
      location ~ ^/index\.php(/|$) {
          include /etc/nginx/fastcgi.conf;
          fastcgi_pass unix:/run/php-fpm-php7.2.socket;
          fastcgi_split_path_info ^(.+?\.php)(/.*)$;
          internal;
      }
  }
  server {
      server_name v2;
      root /srv/api-v2/public/;
  
      location / {
          try_files $uri /index.php$is_args$args;
      }
  
      location ~ ^/index\.php(/|$) {
          include /etc/nginx/fastcgi.conf;
          fastcgi_pass unix:/run/php-fpm-php7.2.socket;
          fastcgi_split_path_info ^(.+?\.php)(/.*)$;
          internal;
      }
  }
  
  </code></pre>