title: Nginx Config for Cors - add_header directive is not allowed
body: <p>I am trying add CORS directive to my nginx file for as simple static HTML site. (taken from here <a href="http://enable-cors.org/server_nginx.html">http://enable-cors.org/server_nginx.html</a>)</p>
  
  <p>Would there be a reason why it would complain about the first add_header directive saying 'add_header" directive is not allowed here'</p>
  
  <p>My config file sample</p>
  
  <pre><code>server {
      if ($http_origin ~* (https?://[^/]*\.domain\.com(:[0-9]+)?)$) {
          set $cors "true";
      }
  
      if ($request_method = 'OPTIONS') {
          set $cors "${cors}options";
      }
  
      if ($request_method = 'GET') {
          set $cors "${cors}get";
      }
      if ($request_method = 'POST') {
          set $cors "${cors}post";
      }
  
      if ($cors = "trueget") {
          add_header 'Access-Control-Allow-Origin' "$http_origin";
          add_header 'Access-Control-Allow-Credentials' 'true';
      }
  
      if ($cors = "truepost") {
          add_header 'Access-Control-Allow-Origin' "$http_origin";
          add_header 'Access-Control-Allow-Credentials' 'true';
      }
  
      if ($cors = "trueoptions") {
          add_header 'Access-Control-Allow-Origin' "$http_origin";
          add_header 'Access-Control-Allow-Credentials' 'true';
          add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
          add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
          add_header 'Content-Length' 0;
          add_header 'Content-Type' 'text/plain charset=UTF-8';
          return 204;
      }
  
      listen 8080;
  
      location / {
          root /var/www/vhosts/mysite;
      }
  }
  </code></pre>