我为我的Rails 4应用程序实现了SSL证书,包括NGinx和puma。我使用了以下 nginx.conf 文件:
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;
}
访问https://
网址时效果很好。但该应用的链接不使用HTTPS协议,因此我在 config / environments / production.rb 中添加了config.force_ssl = true
:
Rails.application.configure do
...
config.force_ssl = true
...
end
然后得到:
This webpage has a redirect loop
从我的浏览器!我寻找了很多来源(包括https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04和https://gist.github.com/rkjha/d898e225266f6bbe75d8),但我并不知道我错过了哪一行。有什么帮助吗?