onlyoffice使用Https访问

开发服务器用的是http,一切正常使用,部署到服务器后,由于服务器使用了Https,导致访问onlyoffice时控制台报错。Mixed Content: The page at 'http://xxxxx//' was loaded over HTTPS, but requested an insecure frame 'http://xxxxx//'.

This request has been blocked; the content must be served over HTTPS.

主要原因是https链接中嵌套了http的资源导致报错,我的onlyoffice部署在docker容器中,如果配置证书什么的,看着还是挺麻烦的。

最简单的办法就是在网页中增加一句代码:

复制代码
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

我用的是官方给的nodejs源码,所以在views/editor.ejs中增加即可。

页面可以正常打开了,但查看网页源代码,发现callback等需要回调地址仍然是http,所以修改docManager.js修改getServerHost函数,我直接把协议名写死了:

复制代码
DocManager.prototype.getServerHost = function getServerHost() {
  return `https://${this.req.headers['x-forwarded-host'] || this.req.headers.host}`
    + `${this.req.headers['x-forwarded-prefix'] || ''}`;
};

但使用中发现问题,文档在线编辑后,没有将文档数据回写到word实体文件中,肯定是回调过程出现了问题,而且从日志中也发现了,onlyoffice在访问/track回写数据时,会自动传过来服务器的url,发现是http,所以修改app.js的这个位置:

复制代码
} else if (bodyTrack.status === 2 || bodyTrack.status === 3) { // MustSave, Corrupted

将返回来的bodyTrack变量修改一下:

复制代码
bodyTrack.url = bodyTrack.url.replace("http", "https");
if (bodyTrack.hasOwnProperty('changesurl')) {
    bodyTrack.changesurl = bodyTrack.changesurl.replace("http", "https");
}

由于我的文档存储路径为了较深的目录,目录层级比较多,为了让创建文档的时候自动创建多级目录,可以修改docManager.js的createDirectory:

复制代码
DocManager.prototype.createDirectory = function createDirectory(directory) {
  if (!this.existsSync(directory)) {
    // 创建多级目录,增加了{ recursive: true }参数
    fileSystem.mkdirSync(directory, { recursive: true });
    //fileSystem.mkdirSync(directory);
  }
};

参考:

This request has been blocked; the content must be served over HTTPS._onlyoffice this request has been blocked; the cont-CSDN博客

相关推荐
Oflycomm35 分钟前
工业以太网四大主流协议(EtherCAT/PROFINET/EtherNet/IP/Modbus)技术参数深度对比
网络·网络协议·tcp/ip·欧飞信·plc模组
wangl_922 小时前
Modbus RTU 与 Modbus TCP 深入指南-现代替代协议
网络·网络协议·tcp/ip·tcp·modbus·rtu
七夜zippoe4 小时前
Python RESTful API设计终极指南:从理论到企业级实战
开发语言·python·http·pandas·restful api
霸道流氓气质5 小时前
SpringAIAlibaba整合 Streamable HTTP 调用免费 MCP Server 实战全解
网络·网络协议·http
ONLYOFFICE5 小时前
如何通过创建插件,自动化Office文档中的重复操作
自动化·编辑器·onlyoffice·插件
winlife_6 小时前
在 Unity Editor 里跑 HTTP MCP server:主线程边界与请求 marshal 的实现要点
http·unity·游戏引擎·多线程·mcp
上海云盾-小余7 小时前
网站木马植入原理与彻底清除、长效防御方案
网络·网络协议·tcp/ip·系统安全
游戏开发爱好者88 小时前
使用Fiddler设置HTTPS抓包诊断Power Query网络问题
android·ios·小程序·https·uni-app·iphone·webview
源远流长jerry9 小时前
TCP 三次握手深度解析:从内核源码到生产实践
linux·运维·网络·网络协议·tcp/ip
加号39 小时前
【Python】 实现 HTTP 网络请求功能入门指南
网络·python·http