I implemented an SSL certificate for my Rails 4 app, with NGinx and puma. I used the following nginx.conf file:
upstream puma {
  server unix:///home/deploy/apps/bestpark/shared/tmp/sockets/bestpark-puma.sock;
}
server {
  listen 80;
  server_name lebonparking.fr;
  rewrite ^/(.*) https://lebonparking.fr/$1 permanent;
}
server {
  listen 443;
  server_name lebonparking.fr;
  ssl on;
  ssl_certificate /home/deploy/apps/bestpark/current/certificates/lebonparking.fr.crt;
  ssl_certificate_key /home/deploy/apps/bestpark/current/certificates/lebonparking.fr.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
  root /home/deploy/apps/bestpark/current/public;
  access_log /home/deploy/apps/bestpark/current/log/nginx.access.log;
  error_log /home/deploy/apps/bestpark/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;
}
And it works fine when accessing https:// URLs. But the links of the app don't use the HTTPS protocol so I added config.force_ssl = true in config/environments/production.rb :
Rails.application.configure do
  ...
  config.force_ssl = true
  ...
end
But then get:
This webpage has a redirect loop
From my browser! I looked for many sources (including https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04 and https://gist.github.com/rkjha/d898e225266f6bbe75d8) but don't know exactly which line I missed. Any help?