title: How do I configure nginx to load try_files from a different folder?
body: <p>I need some help configuring nginx to load files from a different folder. Here is my config:</p>
  
  <pre><code>index index.php;
  
  server {
      server_name domain.com;
      root /www/domain.com/www/;
  
      location / {
              try_files $uri $uri/ /php_www/index.php;
      }
  
      location ~ \.php$ {
              try_files $uri =404;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index /php_www/index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_param PATH_INFO $fastcgi_script_name;
              include /etc/nginx/fastcgi_params;
      }
  
      error_page  404  /404.html;
  
      error_log /var/log/nginx/error.log;
  
  }
  </code></pre>
  
  <p>The problem is that /php_www/ is not located inside the root defined in nginx.</p>
  
  <p>I have 4 different folders that I need to do this with, here is what my folder structure looks like:</p>
  
  <pre><code>/www/domain.com/www/
  /www/domain.com/php_www/
  /www/domain.com/content1/
  /www/domain.com/content2/
  </code></pre>
  
  <p>What I'm trying to do is when a visitor goes to <code>domain.com/page1/content1/</code> I want to load content from the content1 folder, for example. The reason for this is I have several git projects with separate repos...this will enable me to push certain areas of the website to production, without effecting anything else. I'd like to not have all my files/content accessible in the /www folder too, so urls can't be brute force attacked, looking for content.</p>
  
  <p>Hopefully this makes sense!</p>
  
  <h1>Working solution (pulled from <a href="https://stackoverflow.com/questions/11680072/how-do-i-configure-nginx-to-load-try-files-from-a-different-folder#comment15504977_11680573">this</a> comment)</h1>
  
  <pre><code>location ^~ / { 
      root /www/domain.com/php_www/; 
      try_files $uri $uri/ /index.php; 
      location ~* \.(?:php|html)$ { 
          try_files $uri =404; 
          fastcgi_pass 127.0.0.1:9000; 
          include /etc/nginx/fastcgi_params; 
      }
  }
  </code></pre>