title: nginx multiple domain virtual host configuration
body: <p>I'm setting up nginx with multiple domain or wildcard support for convenience sake, rather than setting up 50+ different sites-available/* files.  Hopefully this is enough to show you what I'm trying to do.  Some are static sites, some are dynamic with usually wordpress installed.</p>
  
  <p>If an index.php exists, everything works as expected.</p>
  
  <p>If a file is requested that does not exist (missing.html), a 500 error is given due to the rewrite.  The logged error is:</p>
  
  <blockquote>
    <p>*112 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/missing.html"</p>
  </blockquote>
  
  <p>The basic nginx configuration I'm currently using is:</p>
  
  <p>`</p>
  
  <pre><code>listen 80 default;
  server _;
  
  ...
  
  location / {
      root /var/www/$host;
  
      if (-f $request_filename) {
              expires max;
              break;
      }
  
      # problem, what if index.php does not exist?
  
      if (!-e $request_filename) {
              rewrite ^/(.*)$  /index.php/$1 last;
      }
  }
  
  ...
  </code></pre>
  
  <p>`</p>
  
  <p>If an index.php does not exist, and the file also does not exist, I would like it to error 404.  Currently, nginx does not support multiple condition if's or nested if so I need a workaround.</p>