title: Nginx alias directive not working with php
body: <p>I have an app that is running on Nginx with a working server block like so:</p>
  
  <pre><code>server {
  
    listen 80;
    server_name example.com;
    root /home/deployer/apps/my_app/current/;
    index index.php;
  
    location / {
      index index.php;
      try_files $uri $uri/;
    }
  
    location ~ \.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/home/deployer/apps/shared/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
    }
  
    location /foo {
      root /home/deployer/apps/modules/;
      # tried this:
      # alias /home/deployer/apps/modules/foo/;
      # but php is not working with alias, only with root
    }
  
  }
  </code></pre>
  
  <p>When I visit /foo, Nginx looks in the path /home/deployer/apps/modules/foo/ for an index.php file and it works.</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>I set up a deploy script using capistrano that deploys to the foo directory:</p>
  
  <pre><code>/home/deployer/apps/modules/foo/
  </code></pre>
  
  <p>Capistrano creates a 'current' directory within the 'foo' directory to contain the application files pulled in from Github, so I needed to change the root path to be:</p>
  
  <pre><code>/home/deployer/apps/modules/foo/current/
  </code></pre>
  
  <p>But Nginx appends the location directive to the end of the root directive.... so, when you visit /foo, Nginx tries to look in:</p>
  
  <pre><code>/home/deployer/apps/modules/foo/current/foo/
  </code></pre>
  
  <p>Using alias is supposed to disregard the /foo set in the location directive and serve files from the exact alias path (which the logs confirm is happening), but when I use the alias directive, the php configuration is not being applied correctly and I am getting a 404 returned.</p>
  
  <p>If I go back to the root directive and remove the 'current' directory altogether, it works fine. I need the files to be served from the 'current' directory to work smoothly with the Capistrano deploy, but cannot figure out how to make the alias directive work with php.</p>
  
  <p>Anyone have any ideas or advice, am I missing something?</p>