2016-12-24 7 views
0

IISサーバーを使用してサーバーに使用した静的コンテンツ(CSS/JS)があります。私はこれらのファイルを保持するために、ASP.NETアプリケーションを作成し、私はこれらの線にIISからnginxに切り替えた後のCORS違反

<httpProtocol> 
    <customHeaders> 
    <add name="Access-Control-Allow-Origin" value="*" /> 
    <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
    </customHeaders> 
</httpProtocol> 

を挿入web.configファイル内で、私はnginxのにこのアプリケーションを切り替えています。

Nginx 1.10.2を正しくセットアップしました。

しかし、私はNginxからフォントを取得しようとするたびに、CORSポリシー違反のために要求をブロックします。このリンク(http://enable-cors.org/server_nginx.html)からの助けを取る

enter image description here

私はnginxの設定ファイルに以下の行を追加しているが、それでも同じ問題が

location/{ 
     if ($request_method = 'OPTIONS') { 
      add_header 'Access-Control-Allow-Origin' '*'; 
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
      # 
      # Custom headers and headers various browsers *should* be OK with but aren't 
      # 
      add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
      # 
      # Tell client that this pre-flight info is valid for 20 days 
      # 
      add_header 'Access-Control-Max-Age' 1728000; 
      add_header 'Content-Type' 'text/plain charset=UTF-8'; 
      add_header 'Content-Length' 0; 
      return 204; 
     } 
     if ($request_method = 'POST') { 
      add_header 'Access-Control-Allow-Origin' '*'; 
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
      add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
     } 
     if ($request_method = 'GET') { 
      add_header 'Access-Control-Allow-Origin' '*'; 
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
      add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; 
     } 
     root html; 
     index index.html index.htm; 
     #proxy_cache my_cache; 
     proxy_pass http://127.0.0.1; 
     proxy_cache_methods GET HEAD POST; 
     expires 365d; 
    } 

まま私はなぜフォントにと本当に混乱していますダウンロードできません。面白いのは、私のCSSとJSが正しくダウンロードできることです。問題はフォントだけです。

答えて

0

これはChromeの問題です。nginxの - This bug reportと関係があります。

localhostを開発用に使用する場合は、--disable-web-securityでクロムを開始できます。また、別のブラウザで試すこともできます。

関連する問題