title: Nginx forwarding to another server block when it shouldn't
body: <p>My nginx server has 3 different sites on it, each with its own server block. For security I'll just be using domain1.com, domain2.com and domain3.com instead of the real domains. Domain3 is still pending transfer to my ownership so its not functioning at all yet.</p>
  
  <p>The problems is that whenever you go to domain1.com, it forwards me to domain2.com. As far as I can tell there isn't anything saying that domain1.com should forward to domain2.com. I cleared my DNS cache and all of my browser cache and cookies.</p>
  
  <p>Here is the server_block configuration of domain1.com</p>
  
  <pre><code>#This is for redirecting everyone from www.domain.com to domain.com
  server {
      listen   80; ## listen for ipv4; this line is default and implied
      #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
  
      server_name www.domain1.com;
  
      return 301 https://domain1.com$request_uri;
  }
  
  server {
      #listen 80 default_server;
      #listen [::]:80 default_server ipv6only=on;
  
      listen 443;
  
      server_name domain1.com;
  
      #keepalive_timeout 70;
  
      root /var/www/domain1.com/html;
      index index.php index.html index.htm;
  
      ssl on;
          ssl_certificate /etc/nginx/ssl/domain1.com/ssl.crt;
          ssl_certificate_key /etc/nginx/ssl/domain1.com/ssl.key;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers HIGH:!aNULL:!MD5;
  
      location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          try_files $uri $uri/ =404;
          # Uncomment to enable naxsi on this location
          # include /etc/nginx/naxsi.rules
      }
  
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
          root /var/www/domain1.com/html;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
      #location /RequestDenied {
      #   proxy_pass http://127.0.0.1:8080;    
      #}
  
      #error_page 404 /404.html;
  
      # redirect server error pages to the static page /50x.html
      #
      #error_page 500 502 503 504 /50x.html;
      #location = /50x.html {
      #   root /usr/share/nginx/html;
      #}
  
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
      #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
      #
      #   # With php5-cgi alone:
      #   fastcgi_pass 127.0.0.1:9000;
      #   # With php5-fpm:
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #   deny all;
      #}
  }
  </code></pre>
  
  <p>The domain2.com configuration is as follows:</p>
  
  <pre><code>#This is for redirecting everyone from www.domain.com to domain.com
  server {
      listen   80; ## listen for ipv4; this line is default and implied
      #listen   [::]:80  ipv6only=on; ## listen for ipv6
  
      server_name www.domain2.com;
  
      return 301 https://domain2.com$request_uri;
  }
  server {
      #listen 80;
      #listen [::]:80  ipv6only=on;
  
      listen 443;
      server_name domain2.com;
  
      ssl on;
      ssl_certificate /etc/nginx/ssl/domain2.com/ssl.crt;
      ssl_certificate_key /etc/nginx/ssl/domain2.com/ssl.key;
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  
      ssl_ciphers HIGH:!aNULL:!MD5;
  
      ssl_prefer_server_ciphers on;
  
      root /var/www/domain2.com/html;
      index index.php index.html index.htm;
  
      location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          try_files $uri $uri/ =404;
          # Uncomment to enable naxsi on this location
          # include /etc/nginx/naxsi.rules
      }
  
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
          root /var/www/domain2.com/html;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
      #location /RequestDenied {
      #   proxy_pass http://127.0.0.1:8080;    
      #}
  
      #error_page 404 /404.html;
  
      # redirect server error pages to the static page /50x.html
      #
      #error_page 500 502 503 504 /50x.html;
      #location = /50x.html {
      #   root /usr/share/nginx/html;
      #}
  
      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
      #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
      #
      #   # With php5-cgi alone:
      #   fastcgi_pass 127.0.0.1:9000;
      #   # With php5-fpm:
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
      }
  
      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      #location ~ /\.ht {
      #   deny all;
      #}
  }
  </code></pre>
  
  <p>According to <code>nginx -t</code> there are no configuration problems. Any help would be much appreciated!</p>
  
  <p><a href="http://pastebin.com/CDQ8ZpWn" rel="nofollow">access.log</a></p>