如何解决https请求不安全http页被阻止问题?

Nginx

1 前言

一个问题,一篇文章,一出故事。
笔者最近代理公司应用,发现https的页面有请求不安全的http也被Blocked的问题,浏览器调试详细显示如下,

Mixed Content: The page at 'https://appname.cmdschool.org/main.jsp' was loaded over HTTPS, but requested an insecure frame 'http://appname.cmdschool.org:443/appname/portal/equiplist/dtHistQueryGuiFet.action'. This request has been blocked; the content must be served over HTTPS.

和同事研究发现可以通过修改页面头解决此问题。

2 最佳实践

2.1 创建反向代理配置文件

vim /etc/nginx/conf.d/appname.cmdschool.org_443.conf

加入如下配置,

  location / {
    #...
    proxy_hide_header Content-Security-Policy;
    add_header Content-Security-Policy Upgrade-Insecure-Requests always;
  }

另外,直接在HTML页面中增加如下代码也可以解决此问题,

<head>
    	<meta http-equiv="Content-Security-Policy" content="Upgrade-Insecure-Requests">
</head>

2.2 重载服务使配置生效

systemctl reload nginx.service
systemctl status nginx.service

参阅文档
=================
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests

没有评论

发表回复

Nginx
如何安装配置Oracle Linux 9.x nginx php-fpm环境?

1 前言 一个问题,一篇文章,一出故事。 本章将完成Nginx与PHP-FPM的集成。 2 最佳实践 …

Nginx
Nginx完全指南

《Nginx完全指南-实现高性能负载均衡的进阶实操指南-第三版.pdf)》

Nginx
如何使用Nginx分享文件日志?

1 前言 一个问题,一篇文章,一出故事。 笔者需要分享Squid日志给开发人员调试,于是想到使用Ng …