Question

Rails app on Nginx too err to many redirects

I am trying to install an ruby on rails app using nginx, passenger and a digital ocean web server.

But when I try to open the webiste, i get a too many redirects error: i think the error is to be found in my nginx configuration file.

Could someone help me to solve it?

server {

  if ($host = partecipativa.online) {
    return 301 https://$host$request_uri;
  } # managed by Certbot

    listen 80;
   listen [::]:80 ipv6only=on;

  server_name partecipativa.online;
 return 404; # managed by Certbot


 }


server {

    server_name partecipativa.online;
    client_max_body_size 32M;

    passenger_enabled on;
    passenger_ruby /home/decidim/.rbenv/versions/2.7.1/bin/ruby;

    rails_env    production;
    root         /home/decidim/decidim-app/public;

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/partecipativa.online-0001/fullchain.pem; # manage>    ssl_certificate_key /etc/letsencrypt/live/partecipativa.online-0001/privkey.pem; # mana>    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



}

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @robywars,

First I think the server block that listens to port 80 should be like that:

server {
    listen 80;
    listen [::]:80;
    server_name mysite.com www.mysite.com;
    return 301 https://www.mysite.com$request_uri;
}

Of course where you see mysite.com change it to your actual domain.

If that doesn’t help, then I would recommend checking your Ruby application for some possible redirects. What I see when I curl your domain is, I reach the domain with HTTP, get redirected to HTTPS and then I’m constantly being redirected to:

Location: https://partecipativa.online/system/   
Location: https://partecipativa.online/system/admins/sign_in
Location: https://partecipativa.online/system/

and so on, which leads me to believe it’s highly possible it’s the Ruby App that is causing the issues.