2016-07-11 7 views
0

サイトをhttpsに変更しましたが、コード内の静的ファイルのcdnを使用しました。それは働くことができないとクロムコンソールでは、このようなエラーを示しています。nginxに基づいてアップグレードinsecur-requestを設定する方法

Mixed Content: The page at 'https://a.example.com/static/' was loaded over HTTPS, but requested an insecure stylesheet 'http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css'. This request has been blocked; the content must be served over HTTPS. 

私はこのようなnginxの設定ファイルでadd_header Content-Security-Policy upgrade-insecure-requests;を追加します:

server { 
    listen 80; 
    listen 443; 
    server_name a.example.com; 
    add_header Content-Security-Policy upgrade-insecure-requests; 

    if ($scheme != "https") { 
     return 301 https://$server_name$request_uri; 
     #rewrite^https://$server_name$request_uri? permanent; 
    } 


    ssl on; 
    ssl_certificate /etc/nginx/ssl/example.crt; 
    ssl_certificate_key /etc/nginx/ssl/example.key; 

    ssl_session_timeout 5m; 

    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; 
    ssl_prefer_server_ciphers on; 

    gzip on; 
    gzip_proxied any; 
    gzip_types text/plain application/xml application/json; 
    client_max_body_size 8M; 
    access_log /var/log/nginx/example.log; 
    location/{ 
      proxy_pass http://10.10.10.110:5000; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header Host $host; 
    } 
    location ^~ /static/ { 

      proxy_pass http://10.10.10.110:8888; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header Host $host; 
      #proxy_set_header Content-Security-Policy upgrade-insecure-requests; 
    } 

}

が、それがありませんまだ仕事はありません!誰かがこれを修正する方法を教えてもらえますか? thx :)

+0

ここは私のクロムとnginxバージョンです。クローム: '51.0.2704.84(64ビット)' 'nginx':' 1.4.6 ubuntu' –

答えて

1

upgrade-insecure-requestsnot supported in all browsersです。 SafariとIE。

コードでHTTPリクエストを置き換えることをお勧めします。あなたはそれがあたりなどから呼び出されるプロトコルに、それは相対的なロードするために//を使用することができます。

あなたはHTTPSコンテキストからWebアプリケーションを開いている場合、それはHTTPSプロトコルを使用して、それをロードすることを意味します
//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css 

、そうでない場合HTTPを使用します。

関連する問題