title: Nginx: NonWWW (80) and rewrite one subdomain (443)
body: <p>I have 'www.domain.com' and want to always rewrite it to 'domain.com' (only available through/on port 80)</p>
  
  <p>I also wanted to add subdomain like 'c.domain.com', always rewrited (and only available) to '<a href="https://c.domain.com" rel="nofollow">https://c.domain.com</a>', but i don't really know how to make another rewrite when i have this for WWW->NonWWW.</p>
  
  <p>This is my config:</p>
  
  <pre><code>ssl_certificate /etc/nginx/certs/server.crt;
  ssl_certificate_key /etc/nginx/certs/server.key;
  
  server  {
          listen                     80;
          server_name                www.domain.com;
          # redirect www to non-www
          rewrite                    ^/(.*) http://domain.com/$1 permanent;   
  }
  
  
  
  server {
          listen                     80;
          server_name                domain.com;
          root                       /usr/share/nginx/$host;
          index                      index.php index.html index.htm;
  
          location / {
                  try_files          $uri $uri/ /index.php?$args =404;
                  #try_files          $uri $uri/;
          }
  
          # PHP-FPM
          location ~* \.php$ {
                  try_files          $uri =404;
                  include            fastcgi_params;
                  fastcgi_pass       unix:/var/run/php5-fpm.sock;
                  fastcgi_param      SCRIPT_FILENAME     $document_root$fastcgi_script_name;
                  fastcgi_param      SCRIPT_NAME         $fastcgi_script_name;
          }
  
  }
  
  server {
    listen           443 default_server ssl;
    server_name      c.domain.com;
    root                       /usr/share/nginx/$host;
    index                      index.php index.html index.htm;
  
  }
  </code></pre>
  
  <p>Thanks in advance!</p>