君玉自牧 君玉自牧
首页
  • Linux
  • Nginx
  • MySQL
  • Redis
  • Kafka
  • Docker
  • Jenkins
  • Oneindex
  • Bitwarden
  • Confluence
  • Photogallery
  • 智能手机
  • 上古卷轴
  • 健身记录
  • 站点相关
  • 未完待续
GitHub (opens new window)
首页
  • Linux
  • Nginx
  • MySQL
  • Redis
  • Kafka
  • Docker
  • Jenkins
  • Oneindex
  • Bitwarden
  • Confluence
  • Photogallery
  • 智能手机
  • 上古卷轴
  • 健身记录
  • 站点相关
  • 未完待续
GitHub (opens new window)
  • 技术架构

  • 桌面维护

  • 网络工程

  • 系统运维

  • 环境搭建

  • 容器编排

  • 持续集成

  • 监控告警

  • 项目实践

  • 脚本开发

  • 前端开发

    • Windows 系统搭建 Node.js 环境
    • Vue 开发入门
    • 搭建 VuePress:Github & Aliyun
    • 本地开发:泛(内网)域名解析
    • SSL 证书申请以及自动续期
    • 自动跳转 https 访问网站
      • VUE
      • JavaScript
    • asar 文件解包、修改再打包
  • 后端开发

  • 效率工具

目录

自动跳转 https 访问网站

# VUE

解决方式:注释标签 CPS设置upgrade-insecure-requests作用是让浏览器自动升级请求。

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
1

在服务器的响应头中加入:

header("Content-Security-Policy:upgrade-insecure-requests");
1

页面是 https 的,但是在这个页面包含了大量的 http 资源(图片、iframe等),页面一旦发现存在上述响应头,会在加载 http 资源时自动替换成 https 请求

# JavaScript

HTML 自上而下解析,所以脚本需要放在主页上方;最好的实现方法是服务端或者域名解析的时候做 301 跳转

<script type="text/javascript">
var targetProtocol = "https:";
if (window.location.protocol != targetProtocol)
 window.location.href = targetProtocol +
  window.location.href.substring(window.location.protocol.length);
</script>

<script type="text/javascript">
var hosts = /^(192.168.1.1)/;
    if (window.location.hostname !== 'localhost' && !hosts.test(window.location.hostname)) {
      // 判断非本地 server 时 http 强制转换成 https
      var targetProtocol = "https:";
      if (window.location.protocol != targetProtocol)
      window.location.href = targetProtocol +
      window.location.href.substring(window.location.protocol.length);
    }
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
网页编辑 (opens new window)
最近提交: 2023/03/22, 11:52:35
SSL 证书申请以及自动续期
asar 文件解包、修改再打包

← SSL 证书申请以及自动续期 asar 文件解包、修改再打包→

Theme by Vdoing | Copyright © 2011-2023 | 君玉自牧
粤ICP备15057965号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式