title: nginx multiple domains (www and non-www for each domain)
body: <p>I'm trying to host two domains on an nginx server, with www to non-www redirection. Here are my site configs:</p>
  
  <p><strong>site 1:</strong></p>
  
  <pre><code>server {
      root /var/www/afspraken/;
      index index.html index.htm;
  
      server_name site1.nl;
  
      location / {
          proxy_pass http://127.0.0.1:8000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
  server {
      server_name www.site1.nl;
      return 301 $scheme://site1.nl$request_uri;
  }
  </code></pre>
  
  <p><strong>site 2:</strong></p>
  
  <pre><code>server {
      root /var/www/mijn/;
      index index.html index.htm;
      server_name site2.nl;
  }
  server {
          server_name www.site2.nl;
          return 301 $scheme://site2.nl$request_uri;
  }
  </code></pre>
  
  <p>Three of the four servers work correctly: <code>www.site2.nl</code>, <code>site2.nl</code> and <code>site1.nl</code>. The <code>www.site1.nl</code> server gives me site2 though. What am I doing wrong?</p>