title: route CNAME with nginx and docker
body: <p>I'm trying to achieve <code>api.com =&gt; api.myapp.com</code> without success.</p>
  
  <p><strong>main nginx</strong> run on aws/ec2 on docker and listen to port 80</p>
  
  <pre><code>server {
      listen 80;
      server_name myapp.com;
      location / {
          proxy_pass http://app:80/;
          proxy_set_header X-Real-IP  $remote_addr;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_set_header Host $host;
      }
  }
  
  server {
      listen 80 l;
      server_name api.myapp.com;
      location / {
          proxy_pass http://api:80/;
          proxy_set_header X-Real-IP  $remote_addr;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_set_header Host $host;
      }
  }
  </code></pre>
  
  <p><strong>myapp.com</strong> domain configured </p>
  
  <p><strong>A Record</strong> => @(host) => 1.10.10.30(aws-ec2/ip)</p>
  
  <p><strong>A Record</strong> => api(host) => 1.10.10.30(aws-ec2/ip)</p>
  
  <p>with this configuration it works fine. visiting <code>myapp.com</code> resolves <code>app</code>, and <code>api.myapp.com</code> resolves api service.</p>
  
  <p>(I hope it's ok until now, so let me know if it wrong way to do it)</p>
  
  <h2>the problem</h2>
  
  <p>Now, I want to configure <code>api.com</code> with <code>CNAME</code> <code>api.myapp.com</code>.
  I went to my domain manager(godaddy) and set as:</p>
  
  <p><code>CNAME</code> => <code>www</code> => <code>api.myapp.com</code></p>
  
  <p>when i visit <code>api.com</code> it resolves <code>myapp.com</code> and not <code>api.myapp.com</code></p>
  
  <p>what should i do?</p>