title: Nginx wrong root directory
body: <p>I have the following server settings, and for some reason, my document root is going to the wrong location. Why is it doing that? <code>$1</code> is correct on the <code>return</code> line, but why is it pulling the wrong root?</p>
  
  <p><strong>This block is broken:</strong></p>
  
  <pre><code>server{
      listen 80;
  
      #server_name mission13.io www.mission13.io;
  
      server_name "~^www\.(.*)$";
      return 301 $scheme://$1$request_uri;
  
      root /usr/share/nginx/html/$1;
      index index.php index.html index.htm;
  
      location / {
              try_files $uri $uri/ /index.html;
      }
      include /usr/share/nginx/conf/mission13.io.conf;
      location ~ \.php$ {
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
      }
  }
  </code></pre>
  
  <p><strong>This block works:</strong></p>
  
  <pre><code>server{
      listen 80;
      root /usr/share/nginx/html/diskise.com;
      index index.php index.html index.htm;
  
      server_name diskise.com www.diskise.com;
  
      location / {
              try_files $uri $uri/ /index.html;
      }
      include /usr/share/nginx/conf/diskise.com.conf;
      location ~ \.php$ {
              fastcgi_pass unix:/var/run/php5-fpm.sock;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include fastcgi_params;
      }
  }
  </code></pre>
  
  <p>it is using a <code>root</code> that is set somewhere else, a completely different file.</p>