2016-08-18 44 views
2

我正在设置Rails博客。我正在使用Rails 5和Devise 4.2.0。该应用程序在运行Nginx和Puma的Ubuntu服务器上运行,并与Capistrano一起部署。在Nginx上启用HTTPS(具有有效的SSL证书)并将301重定向表单HTTP添加到HTTPS之前,所有内容都可以在制作中使用。设计:无法验证服务器上启用的HTTPS的CSRF令牌真实性(无JSON/API)

我检查了生产日志和日志中的真实性密钥与我在浏览器中看到的不一致。

这里是我使用的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; 
} 

有谁知道可能会在这里吗? 让我知道你是否需要更多信息。

感谢

回答

5

新增proxy_set_header X-Forwarded-Proto $scheme;到了它去的location @puma

+0

非常感谢,它节省了我的一天。我有完全相同的问题,你的解决方案就像一个魅力。任何解释? –

+0

@CupraR_On_Rails据我所知,它允许Rails应用程序查看请求所来的http协议,并在生成真实性令牌时使用它。 – slehmann36

+0

对我很有帮助,谢谢。 –

相关问题