title: nginx configuration with multiple location blocks
body: <p>I'm trying to configure nginx to serve 2 different php scripts from 2 different location. The configuration is as follows.  </p>
  
  <ol>
  <li>I have a Laravel installation which resides in <code>/home/hamed/laravel</code> in which its <code>public</code> directory should be served.  </li>
  <li>I have a Wordpress installation in <code>/home/hamed/www/blog</code>.</li>
  </ol>
  
  <p>And this is my <code>nginx</code> configuration:</p>
  
  <pre><code>server {
          listen  443 ssl;
          server_name example.com www.example.com;
  
          #root /home/hamed/laravel/public;
  
          index index.html index.htm index.php;
  
          ssl_certificate /root/hamed/ssl.crt;
          ssl_certificate_key /root/hamed/ssl.key;
  
          location /blog {
                  root /home/hamed/www/blog;
                  try_files $uri $uri/ /blog/index.php?do=$request_uri;
          }
  
          location / {
                  root /home/hamed/laravel/public;
                  try_files $uri $uri/ /index.php?$request_uri;
          }
          error_page 404 /404.html;
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
                  root /usr/share/nginx/html;
          }
  
          location ~ \.php$ {
                  try_files $uri =404;
                  fastcgi_split_path_info ^(.+\.php)(/.+)$;
                  #fastcgi_pass 127.0.0.1:9000;
                  fastcgi_pass unix:/var/run/php5-fpm.hamed.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
          }
  
  }
  </code></pre>
  
  <p>The problem is when trying to access the wordpress section by calling <code>example.com/blog</code> still the the laravel installtion takes over the request.  </p>
  
  <p>Now I have tried replacing <code>root</code> directive inside <code>location</code> blocks with <code>alias</code> to no avail.  </p>
  
  <p>According to <a href="https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms" rel="noreferrer">this guide</a> having the <code>index</code> directive or <code>try_files</code> inside <code>location</code> triggers an internal redirect which I suspect causes this behavior.</p>
  
  <p>Would someone please help me figure this out?</p>