title: Nginx redirecting to wrong vhost
body: <p>I have around 1300vhosts in one nginx conf file. All with the following layout (they are listed after each other in the vhost file). </p>
  
  <p>Now my problem is that sometimes my browser redirects site2 to site1. For some reason, while the domain names don't event match.</p>
  
  <p>It looks like nginx is always redirecting to the first site in the vhosts file.</p>
  
  <p>Somebody that know what this problem can be?</p>
  
  <pre><code>server {
      listen   80;
  
      server_name site1.com;
      rewrite ^(.*) http://www.site1.com$1 permanent;
  }
  
  server {
      listen   80;
  
      root /srv/www/site/public_html/src/public/;
      error_log /srv/www/site/logs/error.log;
      index index.php;
  
     server_name www.site1.com;
  
      location / {
          if (!-e $request_filename) {
              rewrite ^.*$ /index.php last;
          }
      }
  
      location ~ .(php|phtml)$ {
          try_files $uri $uri/ /index.php;
          fastcgi_param SCRIPT_FILENAME /srv/www/site/public_html/src/public$fastcgi_script_name;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  }
  
  server {
      listen   80;
  
      server_name site2.com;
      rewrite ^(.*) http://www.site2.com$1 permanent;
  }
  
  server {
      listen   80;
  
      root /srv/www/site/public_html/src/public/;
      error_log /srv/www/site/logs/error.log;
      index index.php;
  
     server_name www.site2.com;
  
      location / {
          if (!-e $request_filename) {
              rewrite ^.*$ /index.php last;
          }
      }
  
      location ~ .(php|phtml)$ {
          try_files $uri $uri/ /index.php;
          fastcgi_param SCRIPT_FILENAME /srv/www/site/public_html/src/public$fastcgi_script_name;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  }
  </code></pre>
  
  <p>EDIT
  Maybe another thing to mention is that, I reload all this vhosts every 2 minutes with nginx -s reload.</p>
  
  <p>On the first tests it looks like the redirection only happens when reloading... Going to do some more tests, but this could be helpful..</p>