HTTP Origin标头(https://example.com)与request.base_url(http://example.com)导轨不匹配

时间:2018-11-20 19:31:02

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

我在https上运行带有puma的Nginx服务器。我将Letsencrypt配置为SSL验证。问题是服务器运行正常,但是当我尝试通过设计创建用户时会抛出此错误

“ HTTP原始标头(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;
  }

1 个答案:

答案 0 :(得分:0)

我的设置与您完全相同,并且我正在使用以下代理配置:

  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可能导致了您的问题,在代理后面没有必要。