title: Set up nginx to allow cross-domain request for subdomain
body: <p>I've got two domains:</p>
  
  <p>domain.com
  sub.domain.com</p>
  
  <p>domain.com needs to make an ajax request to sub.domain.com. I realize that the browser will block this if the request is hardcoded to be sub.domain.com. I tried the following nginx conf:</p>
  
  <pre><code>server {
      server_name domain.com;
  
      rewrite ^/api/(.*)$ http://sub.domain.com/api/$1; }
  </code></pre>
  
  <p>However, I still get the following error in the browser (Chrome):</p>
  
  <pre><code>No 'Access-Control-Allow-Origin' header is present on the requested resource.
  </code></pre>
  
  <p>How can I set up nginx to instruct the browser to allow cross domain requests between domain.com and sub.domain.com?</p>
  
  <p>Thanks!</p>