Too many redirects error while trying to configure rails application as SSL using nginx and unicorn

前端 未结 2 900
星月不相逢
星月不相逢 2021-02-04 03:42

I am trying to configure a Rails application with SSL, using Nginx and Unicorn. I am trying to set it up locally. For that I first created a self-signed certificate using OpenS

相关标签:
2条回答
  • 2021-02-04 04:20

    You are missing a header:

    proxy_set_header X-Forwarded-Proto https;
    

    Let me cite a comprehensive post that explains nicely how Rails deals with HTTPS on Nginx:

    force_ssl relies on the HTTP_X_FORWARDED_PROTO HTTP header to determine whether or not the request was an HTTPS request. If this setting isn't set to https then you will end up with an infinite redirect loop as force_ssl will always think the forwarded request isn't HTTPS.

    0 讨论(0)
  • 2021-02-04 04:34

    Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

    Try changing 'rewrite ^/(.*) http://...' to 'rewrite ^/(.*) https://...' and remove listen 80 from the 2nd server block

    ~ answer per house9

    0 讨论(0)
提交回复
热议问题