title: conflicting server name on nginx
body: <p>Not know why I got  <code>conflicting server name</code> exception.</p>
  
  <p>I accept the request with <code>WWW</code> in the prefix or not.</p>
  
  <p>And <code>return 301 https://$server_name$request_uri;</code> is to force non https request to https.</p>
  
  <p>Any idea how to solve this exception?</p>
  
  <h1>Nginx.conf</h1>
  
  <pre><code>server {
      listen      80 ;
      server_name myApp.co www.myApp.co;
  
      root  /home/deployer/workspace/myApp-web/dist;
      error_log /var/log/nginx/myApp_web_error.log warn;
      access_log /var/log/nginx/myApp_web_access.log;
      listen 443 ssl;
      listen [::]:443 ssl;
  
      ssl_certificate /etc/nginx/ssl/myApp_co.bundled.crt;
      ssl_certificate_key /etc/nginx/ssl/myApp.key;
      large_client_header_buffers 4 4800k;
  
  
      location / {
          try_files $uri $uri/ /index.html ; # make HTML5 workable
          gzip on;
          gzip_static on;
          gzip_min_length 1k;
          gzip_comp_level 6;
          gzip_types application/javascript text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
          gzip_vary off;
          gzip_disable "MSIE [1-6]\.";
      }
  
      location /api/v1 {
          proxy_pass http://localhost:7617/api/v1/;
      }
  }
  
  server {
       listen      80;
       server_name myApp.co www.myApp.co;
       return 301 https://$server_name$request_uri;
   }
  </code></pre>
  
  <h1>Exception log</h1>
  
  <pre><code>    2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored
      2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored
      2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored
      2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored
      2017/12/05 06:55:06 [warn] 6093#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored
  </code></pre>