force_ssl causes never-ending redirects

2019-07-19 17:31发布

Rails 3.1.3

With force_ssl in place I get this redirect over and over and it never ends. I am going to the https url so I'm not sure why else it would complain. Ideas?

Started GET "/app/admin/calendar" for 69.64.227.254 at 2012-02-13 19:52:44 +0000
  Processing by Admin::CalendarsController#show as HTML
  User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 21 ORDER BY lower(first) ASC LIMIT 1
  Account Load (0.6ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 23 AND (accounts.deleted_at IS NULL) LIMIT 1
Redirected to https://www.mydomain.net/app/admin/calendar
Completed 301 Moved Permanently in 4ms

2条回答
神经病院院长
2楼-- · 2019-07-19 18:05

Answered here: Why am I getting infinite redirect loop with force_ssl in my Rails app?

Spoiler: add this to your nginx config file:

proxy_set_header X-Forwarded-Proto $scheme;
查看更多
姐就是有狂的资本
3楼-- · 2019-07-19 18:08

If you are using config.force_ssl = true and end up in an infinite loop, try this:

In your nginx config change:

listen 443 default ssl;

to:

listen 443;
ssl on;

Credits to pjammer: Nginx configuration leads to endless redirect loop

查看更多
登录 后发表回答