title: subdomains using NGINX and Codeigniter
body: <p>I'd like to have various subdomains on my site such as: <code>biology.mysite.com</code>.</p>
  
  <p>Currently I have the following in my nginx.conf:</p>
  
  <pre><code>server {
    listen 80;
    server_name biology.mysite.com;
    return 301  https://mysite.com/tags/biology$request_uri;
  }
  </code></pre>
  
  <p>This code works in that if you point the browser to <code>biology.mysite.com</code>, it redirects to <code>https://mysite.com/tags/biology</code> and the correct biology content loads. </p>
  
  <p>However, I <strong>don't</strong> want to redirect the url but want to keep the subdomain as the url.</p>
  
  <p>So I replaced the above with the code below based on <a href="https://gist.github.com/lynxluna/1050850" rel="nofollow">this gist</a> but it has no effect (meaning pointing to <code>biology.mysite.com</code> simply goes to <code>mysite.com</code>): </p>
  
  <pre><code>      if ($host ~* ^www\.([a-z0-9]*)\.(mysite\.com) )
        {
            set $tagname $1;
            set $host_without_www $2;
            rewrite ^/(.*)$ $scheme://$tagname.$host_without_www/ permanent;
        }
  
        if ($host ~* ^([a-z0-9]+)\.(mysite\.com))
        {
            set $tagname $1;
              set $host_without_www $2;
  
              rewrite ^/$ /index.php/tags/index/ last;
              rewrite ^/(.+)$ /index.php/$1 last;
        }
  </code></pre>
  
  <p>Thoughts?</p>
  
  <p><strong>Note</strong> the reason I posted this here rather than <a href="http://serverfault.com">Serverfault</a> is b/c I'm using the Codeigniter framework (which has a unique routing scheme) and so the answer might involve knowledge of NGINX and Codeigniter.</p>