【问题标题】:HTTP Origin header (https://example.com) didn't match request.base_url (http://example.com) railsHTTP Origin 标头 (https://example.com) 与 request.base_url (http://example.com) rails 不匹配
【发布时间】:2019-04-23 07:47:48
【问题描述】:

我在 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;
  }

【问题讨论】:

  • 可能是个愚蠢的问题,但我知道有一些 nginx 选项取决于顺序:您是否尝试将 proxy_pass 放在 proxy_set_header 之前?这是我在您的配置和您引用的配置之间看到的唯一明显区别。
  • @chrisHall 我不认为,这取决于订单,但我仍然尝试过,但没有成功。

标签: ruby-on-rails ruby nginx puma nginx-config


【解决方案1】:

我的设置与您完全相同,我的设置是使用以下代理配置:

  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 可能导致您的问题,它不是代理背后的必要条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-19
    • 2016-01-16
    • 2015-05-21
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多