如何基于nginx

问题描述 投票:0回答:2
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:)
    

意识到,所有浏览器中都不支持

upgrade-insecure-requests

,例如野生动物园和即
google-chrome nginx https
2个回答
4
投票
//

将其相对加载,相对于其从per:

//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css


意味着,如果您是从HTTPS上下文打开Web应用程序,它将使用HTTPS协议加载它,否则它将使用HTTP.

对于其他任何遇到此问题的人,想要一种更好的方式,可以在所有浏览器中工作(尽管理论上一切都应该支持它,而不是IE)

随附的文件就是您将在每个服务器上重复使用的标准NGINX设置的位置,而TLS是所有您刚刚设置的“ SSL”配置。
to to to to to端口80的任何东西都会被重新定向到HTTPS站点,还可以添加内容安全性 - 如果您有任何不安全的链接,则该链接将确保浏览器(如果浏览器支持)直接将其直接用于HTTPS URL,则可以防止它。向HTTP网站提出额外要求,然后重定向

该配置还将基本域请求重定向到www。这样您就可以轻松地设置静态内容的无用域(只需添加与最后一个类似的配置,但对于static.example.com)

从理论上讲,如果基本域和端口80配置专门针对其任务,则可以更有效地更有效,并且必须在主网站上进行更少的处理以说明这些方案。

1
投票

我认为您应该添加

always

以确保即使在错误响应中发送标头。

add_header Content-Security-Policy "upgrade-insecure-requests" always;


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.