gpt4 book ai didi

ruby-on-rails - treSTLe HTTP Origin header (https :.。)。与 request.base_url (http://) 不匹配

转载 作者:太空宇宙 更新时间:2023-11-03 14:28:08 26 4
gpt4 key购买 nike

我在 Rails 中使用 TreSTLe Admin 并已将我的服务器配置为接受 SSL 连接。在 localhost 中,它运行良好,但是当我尝试转移到生产环境时,我收到以下错误:

Completed 200 OK in 2ms (Views: 1.5ms)
I, [...T16:52:04.341111] INFO: Started POST "/admin/login" for 190.12.77.81 at 2019-03-11 16:52:04 +0000
I, [...T16:52:04.341928] INFO: Processing by Trestle::Auth::SessionsController#create as HTML
I, [...T16:52:04.342009] INFO: Parameters: {"utf8"=>"✓", "authenticity_token"=>"UpwtvP0sNUrNqQazOh9BiLEv0uuOi75shw/leYNDJrPC9jpv7Qv9ShzZvFslBakHO+NjTtJPQ7bphiMbaBXzKg==", "email"=>"admin@silbia.com", "password"=>"[FILTERED]", "commit"=>"Login"}
W, [...T16:52:04.342504] WARN: HTTP Origin header (https://wog.uye.pe) didn't match request.base_url (http://wog.uye.pe)

HTTP Origin header ( https://example.com ) 与 request.base_url ( http://example.com ) rails 不匹配

我该如何解决这个问题?

最佳答案

你可以创建一个中间件:

# frozen_string_literal: true

require 'json'

class CloudflareProxy
def initialize(app)
@app = app
end

def call(env)
return @app.call(env) unless env['HTTP_CF_VISITOR']

env['HTTP_X_FORWARDED_PROTO'] = JSON.parse(env['HTTP_CF_VISITOR'])['scheme']
@app.call(env)
end
end

config/application.rb中使用:

config.middleware.use CloudflareProxy

CF-Visitor header 的引用:

https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-

CF-Visitor

A JSON object containing only one key called scheme. The value is identical to that of X-Forwarded-Proto (either HTTP or HTTPS). CF-Visitor is only relevant if using Flexible SSL.

关于ruby-on-rails - treSTLe HTTP Origin header (https :.。)。与 request.base_url (http://) 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55109859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com