码上风云

记录精彩的程序人生

  menu
24 文章
0 浏览
0 当前访客
ღゝ◡╹)ノ❤️

nginx反向代理到Https后,请求Http资源报错blocked mixed-content

在 sever 里面添加配置即可:

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

下面是我的配置:

# HTTPS server
#
server {
    listen       443 ssl;
    server_name  xxx.com;
    ssl_certificate      cert/xxx.pem;
    ssl_certificate_key  cert/xxx.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
   #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers  on;
	
    #重要http转https
    add_header Content-Security-Policy upgrade-insecure-requests;
	
    location / {
        proxy_pass   http://localhost:8080/;
	proxy_set_header Host $http_host;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-Proto https;
        client_max_body_size 128m;
    }

think twice, code once