Rails https 站点使用 rails-kindeditor

ecloud · August 29, 2017 · Last by ecloud replied at August 29, 2017 · 1914 hits

本来网站是用的 http,之后要求使用 https,加上 https 之后,kindeditor 上传功能彻底失效。我用 chrome 查看,发现 kindeditor 使用的路径还是 http,有什么配置办法改变

goole 到一个 issue,好几年都没回复,特来请求 rails 大神解答。

看源码,搞明白这个 gem 是如何生成上传的 url 的,看到你这个问题的时候,我去找了这个 gem 的源码,简单翻了一下源码,这是与你问题相关的关键源码

https://github.com/Macrow/rails_kindeditor/blob/master/lib/rails_kindeditor/helper.rb#L52-L58

调试一下,看你跑完这段代码的时候,生成的 url 的 schema 部分是否是你所期望的

同时注意配置:https://github.com/Macrow/rails_kindeditor#asset-host-options-configuration

最后,看一下你的 web(nginx/apache)配置是否正确,如 nginx

proxy_set_header   X-Forwarded-Proto  $scheme;

另外,再次贴上:https://ruby-china.org/topics/24325

app.root_url 默认会返回 http://www.example.com/

@w7938940 请问有什么办法可以自动识别 http 和 https 吗?

Reply to ecloud

试试在 production.rb 添加

config.action_controller.default_url_options = {
  host: 'yourdomain.com',
  protocol: 'https'
}

@w7938940 非常感谢,添加之后main_app.root_path变成了https://yourdomain.com

ecloud closed this topic. 29 Aug 16:40
You need to Sign in before reply, if you don't have an account, please Sign up first.