Ruby on rails 设计:Can';t验证服务器上启用的HTTPS的CSRF令牌真实性(无JSON/API)

Ruby on rails 设计:Can';t验证服务器上启用的HTTPS的CSRF令牌真实性(无JSON/API),ruby-on-rails,ssl,nginx,devise,csrf-protection,Ruby On Rails,Ssl,Nginx,Devise,Csrf Protection,我正在建立一个Rails博客。我正在使用Rails 5和Desive 4.2.0。该应用程序使用Nginx和Puma在Ubuntu服务器上运行,并使用Capistrano进行部署。在Nginx上启用HTTPS(具有有效的SSL证书)并将301重定向表单HTTP添加到HTTPS之前,一切都在生产中运行良好 我已经检查了生产日志,日志中的真实性密钥与我在浏览器中看到的密钥不匹配 下面是我正在使用的nginx.conf文件: upstream puma { server unix:///home/

我正在建立一个Rails博客。我正在使用Rails 5和Desive 4.2.0。该应用程序使用Nginx和Puma在Ubuntu服务器上运行,并使用Capistrano进行部署。在Nginx上启用HTTPS(具有有效的SSL证书)并将301重定向表单HTTP添加到HTTPS之前,一切都在生产中运行良好

我已经检查了生产日志,日志中的真实性密钥与我在浏览器中看到的密钥不匹配

下面是我正在使用的nginx.conf文件:

upstream puma {
  server unix:///home/deploy/apps/example-blog/shared/tmp/sockets/example-blog-puma.sock;
}

server { # Redirect HTTP to HTTPS
  # Bind port(s)
  listen   80;
  listen   [::]:80;

  # Bind domain(s)
  server_name blog.example.com;

  # 301 redirect to HTTPS
  return 301 https://$server_name$request_uri;
}

server { # Primary server block
  # Bind port(s)
  listen   443 default_server ssl;

  # Bind domain(s)
  server_name blog.example.com;

  # Bind certificate(s)
  ssl_certificate       /etc/nginx/ssl/blog.example.com/ssl-bundle.crt;
  ssl_certificate_key   /etc/nginx/ssl/blog.example.com/blog.example.com.key;

  root /home/deploy/apps/example-blog/current/public;
  access_log /home/deploy/apps/example-blog/current/log/nginx.access.log;
  error_log /home/deploy/apps/example-blog/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}
有人知道这里发生了什么吗? 如果你需要更多的信息,请告诉我


感谢

添加了
proxy\u set\u header X-Forwarded-Proto$方案
位置@puma
去,这让它运行起来。

非常感谢,它节省了我的时间。我也有同样的问题,你的解决方案很有魅力。有什么解释吗?@CupraR_On_Rails据我所知,它允许Rails应用程序查看请求所使用的http协议,以及生成真实性令牌时使用的http协议。