title: How to use Nginx alias to load PHP from other directory?
body: <p>I want to make a sub directory my on web server, <code>system</code> that serves a backend from another folder for people, but I am having some difficulty.</p>
  
  <p>The server configuration should translate <code>system</code> as <code>index.php</code> of the <code>/srv/www/xxx/backend/web</code>, essentially <code>system</code> should alias to the index of another directory.</p>
  
  <p>I have a configuration like:</p>
  
  <pre><code>location /system {
      alias /srv/www/xxx/backend/web;
      rewrite ^(.*) /index.php?r=$1;
      return 200 $document_root$fastcgi_script_name;
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          try_files $uri =404;
  
          # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
      }
  }
  
  location / {
      rewrite /(.*) /index.php?r=$1;
  }
  
  location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      try_files $uri =404;
  
      # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
  }
  </code></pre>
  
  <p>I have tried numerous iterations (including using <code>root</code>), however even though I can get:</p>
  
  <pre><code>return 200 $document_root$fastcgi_script_name;
  </code></pre>
  
  <p>to give me:</p>
  
  <pre><code>/srv/www/xxx/backend/web/index.php
  </code></pre>
  
  <p>and I have vi'ed into this file to make sure it works when I take out the return wget gives me a 404. I am sure I am missing something really simple.</p>
  
  <p>Can someone help me understand what is wrong?</p>