This question already has answers here:
https redirect for rails app behind proxy?
(2个答案)
4年前关闭。
我使用NGinx和puma为我的Rails 4应用实现了SSL证书。我使用了以下nginx.conf文件:
访问
但是然后得到:
从我的浏览器!我寻找了许多来源(包括https://www.digitalocean.com/community/tutorials/how-to-create-an-ssl-certificate-on-nginx-for-ubuntu-14-04和https://gist.github.com/rkjha/d898e225266f6bbe75d8),但不知道确切错过了哪一行。有什么帮助吗?
(2个答案)
4年前关闭。
我使用NGinx和puma为我的Rails 4应用实现了SSL证书。我使用了以下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://
URL时,它可以正常工作。但是应用程序的链接不使用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),但不知道确切错过了哪一行。有什么帮助吗?
最佳答案
您需要设置标题,以便Rails知道它正在通过https获取流量。 Checkout this answer
关于ruby-on-rails - 使用Rails 4,NGinx和puma获得无限重定向循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33701305/