2016-08-18 2 views
2

Rails 블로그를 설정 중입니다. 레일 5와 Devise 4.2.0을 사용하고 있습니다. 이 앱은 Nginx와 Puma가있는 Ubuntu 서버에서 실행되며 Capistrano와 함께 배포됩니다. Nginx에서 HTTPS (유효한 SSL 인증서 사용)를 사용하고 HTTP에서 HTTPS로 301 리디렉션 양식을 추가 할 때까지 모든 것이 제작 과정에서 훌륭하게 작동합니다.Devise : 서버에서 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; 
} 

사람이 여기에 갈 수있는 무엇을 알고 있나요? 더 자세한 정보가 필요하면 알려주세요.

감사 진행을받은 location @puma

답변

5

추가 proxy_set_header X-Forwarded-Proto $scheme;.

+0

덕분에 많은 시간을 절약 할 수있었습니다. 나는 똑같은 문제를 가지고 있었고 당신의 솔루션은 매력처럼 작동합니다. 설명이 뭐야? –

+0

@CupraR_On_Rails 내가 이해할 때, 그것은 Rails 앱이 요청이 들어오는 HTTP 프로토콜을 볼 수있게하고 인증 토큰을 생성 할 때 사용된다. – slehmann36

+0

감사합니다. –

관련 문제