【发布时间】:2019-09-25 06:31:57
【问题描述】:
在 Rails 5.2,SSL 环境中,使用 Nginx 作为 reverse_proxy 运行,每当我提交表单时都会收到错误:
HTTP Origin 标头 (https://agro2business.com.br) 不匹配 request.base_url (https://agro2business.com.br, agro2business.com.br)
在 1 毫秒内完成 422 个不可处理的实体(ActiveRecord:0.0 毫秒)
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)
我在另一个 StackOverflow 问题中阅读了有关配置参数和 Nginx 以传递标头的信息,但到目前为止还没有运气。我的 nginx 配置文件:
proxy_pass http://localhost:4000; }
位置/{
proxy_pass http://localhost:4000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Real-Port $server_port; proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Ssl on; }
为什么 Rails 会尝试将标题与两个值进行比较?
request.base_url (https://agro2business.com.br, agro2business.com.br)
【问题讨论】:
-
你在使用设计吗?
-
@a3y3 是的,我正在使用 Devise gem
-
很可能是表单中没有传递CSRF token。搜索如何将其包含在您的 POST 请求中。
标签: ruby-on-rails ssl nginx ruby-on-rails-5