ruby-on-rails - HTTP Origin 标头 (https://example.com) 与 request.base_url (http://example.com) rails 不匹配
问题描述
我在 https 上运行带有 puma 的 Nginx 服务器。我为 SSL 验证配置了 Letsencrypt。问题是服务器运行良好但是当我尝试通过设计创建用户时会抛出此错误
“HTTP Origin 标头 ( https://example.com ) 与 request.base_url ( http://example.com )不匹配”
我尝试修改此处指定的 nginx.conf 配置 https://github.com/rails/rails/issues/22965#issuecomment-172929004
但是,这里没有运气是我的配置文件
upstream puma {
server unix:///home/ubuntu/blue_whale/example/shared/tmp/sockets/gofickle-puma.sock;
}
server
{
listen 443 ssl default;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /home/ubuntu/blue_whale/example/current/public;
access_log /home/ubuntu/blue_whale/example/current/log/nginx.access.log;
error_log /home/ubuntu/blue_whale/example/current/log/nginx.error.log info;
add_header Strict-Transport-Security “max-age=31536000”;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Ssl on; # Optional
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Host $host;
proxy_pass http://puma;
}
解决方案
我的设置与您完全相同,我正在使用以下代理配置:
location @rails {
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_redirect off;
proxy_pass http://rails_app;
}
我认为可能是 X-Forwarded-Proto 和 SSL 可能会导致您的问题,在代理后面没有必要。
推荐阅读
- python-3.x - 如果按钮在列表中,如何编辑按钮上的文本?
- sql - 存储实体时 Oracle 错误 01843 不是有效月份
- vba - 更新到 Office 365 后找不到默认收件箱
- python - 为模型提供服务时,找不到名称为空的张量
- javascript - 在 Ubuntu 18.04 上使用 Sequelize 时收到错误。Mac 上完全相同的文件不会发生错误
- email - 如何加密消息node.js sendmail?
- svg - circle 和 stroke-dasharray 的跨浏览器 SVG 渲染问题
- php - 推进 ORM v1.6 中的 UNION 查询
- python - 如何在 RNN 中正确使用 Dropout
- node.js - 如何使用 Python3 将 .wav 文件流式传输到 websocket(我有一个工作节点示例)