title: Emulating Apache Directory Alias on Nginx
body: <p>With <code>Apache</code> we can do something like this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerAdmin webmaster@localhost
          DocumentRoot /var/www/app1/public
          &lt;Directory /&gt;
                  Options +Indexes +FollowSymLinks +MultiViews
                  AllowOverride FileInfo
                  Require all granted
          &lt;/Directory&gt;
  
          Alias /app2 "/var/www/app2/public"
          &lt;Directory "/var/www/app2/public"&gt;
                  DirectoryIndex index.php
                  Options +Indexes +FollowSymLinks +MultiViews
                  AllowOverride All
                  Require all granted
          &lt;/Directory&gt;
  
          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
          &lt;Directory "/usr/lib/cgi-bin"&gt;
                  AllowOverride None
                  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                  Order allow,deny
                  Allow from all
          &lt;/Directory&gt;
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
          # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
          LogLevel warn
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>So, in this approach I have two different applications:</p>
  
  <ul>
  <li>App 1 (Main app) -> <code>www.mydomain.com/something</code></li>
  <li>App 2 (Another sub app) -> <code>www.mydomain.com/app2/login</code></li>
  </ul>
  
  <p>Both was developed with Laravel (PHP Framework) and need to receive <code>QUERY STRING</code> to work.</p>
  
  <p>I wanna move to <code>Nginx</code> and currently my config is this:</p>
  
  <pre><code>server {
  
      listen 80;
      server_name host.com;
      root /var/www/app1/current/public;
  
      index index.php;
      charset utf-8;
  
      # App 1
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      location ~ ^/index\.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_intercept_errors off;
          fastcgi_buffer_size 16k;
          fastcgi_buffers 4 16k;
      }
  
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
  
      access_log off;
      error_log  /var/log/nginx/app.log error;
  
      sendfile off;
      client_max_body_size 100m;
  
      location ~ /\.ht {
          deny all;
      }
  }
  </code></pre>
  
  <p>The <code>app1</code> (root application) works fine. The issue is: How can I set the <code>app2</code> in that config file?</p>
  
  <p>I've tried:</p>
  
  <pre><code># App 2
  location ^~ /app2 {
      alias /var/www/app2/current/public;
      try_files $uri $uri/ /index.php?$query_string;
  }
  </code></pre>
  
  <p>But, without success.</p>