title: nginx - two subdomain configuration
body: <p>I'm new to Nginx and I'm trying to get subdomains working.</p>
  
  <p>What I would like to do is take my domain (let's call it <code>example.com</code>) and add:</p>
  
  <ul>
  <li><code>sub1.example.com</code>,</li>
  <li><code>sub2.example.com</code>, and also have</li>
  <li><code>www.example.com</code> available.</li>
  </ul>
  
  <p>I know how to do this with Apache, but Nginx is being a real head scratcher.</p>
  
  <p>I'm running Debian 6.</p>
  
  <p>My current /etc/nginx/sites-enabled/example.com:</p>
  
  <pre><code>server {
      server_name www.example.com example.com;
      access_log /srv/www/www.example.com/logs/access.log;
      error_log /srv/www/www.example.com/logs/error.log;
      root /srv/www/www.example.com/public_html;
  
      location / {
          index  index.html index.htm;
      }
  
      location ~ \.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
      }
  }
  </code></pre>
  
  <p>It is working to serve example.com and www.example.com. </p>
  
  <p>I have tried to add a second server block in the same file like:</p>
  
  <pre><code>server {
          server_name www.example.com example.com;
          access_log /srv/www/www.example.com/logs/access.log;
          error_log /srv/www/www.example.com/logs/error.log;
          root /srv/www/www.example.com/public_html;
  
          server {
              server_name sub1.example.com;
              access_log /srv/www/example.com/logs/sub1-access.log;
              error_log /srv/www/example.com/logs/sub1-error.log;
              root /srv/www/example.com/sub1;
      }
          location / {
              index  index.html index.htm;
          }
  
          location ~ \.php$ {
              include /etc/nginx/fastcgi_params;
              fastcgi_pass 127.0.0.1:9000;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
          }
  }
  </code></pre>
  
  <p>No luck. Any ideas? I'd super appreciate any feedback.</p>