Rails / Nginx / Devise redirecting to http on login

0

Hello,

I am not an underdog, I am a mere programmer enslaved by the stupidity of anyone who has money.

That said, my doubt.

Rails / nginx / certbot / DigitalOcean / devise are the cause of the problem, I think it's the main nginx, the configuration in / etc / nginx / sites-available is this:

upstream puma_myapp_web_production {
  server unix:/var/www/myapp_web/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  server_name myapp.mydomain.net;
  root /var/www/myapp_web/current/public;
  try_files $uri/index.html $uri @puma_myapp_web_production;

  client_max_body_size 4G;
  keepalive_timeout 10;

  error_page 500 502 504 /500.html;
  error_page 503 @503;

  location @puma_myapp_web_production {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Forwarded-Proto http;
    proxy_pass http://puma_myapp_web_production;
    # limit_req zone=one;
    access_log /var/www/myapp_web/shared/log/nginx.access.log;
    error_log /var/www/myapp_web/shared/log/nginx.error.log;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location = /50x.html {
    root html;
  }

  location = /404.html {
    root html;
  }

  location @503 {
    error_page 405 = /system/maintenance.html;
    if (-f $document_root/system/maintenance.html) {
      rewrite ^(.*)$ /system/maintenance.html break;
    }
    rewrite ^(.*)$ /503.html break;
  }

  if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/myapp.mydomain.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/myapp.mydomain.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = myapp.mydomain.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  server_name myapp.mydomain.net;
    listen 80;
    return 404; # managed by Certbot


}

The site opens normal and in HTTPS, it shows the login screen, but it does not log, it can even create users and save to the bank, but it does not login. When you log in, it returns you to the HTTPS login page.

In production.log show me this:

I, [2018-12-04T15:15:24.699170 #3799]  INFO -- : [8b6bdcfa-8079-421b-9dca-d8efcc0b29a3] Started GET "/" for 179.176.23.59 at 2018-12-04 15:15:24 +0000
I, [2018-12-04T15:15:24.702207 #3799]  INFO -- : [8b6bdcfa-8079-421b-9dca-d8efcc0b29a3] Processing by DashboardController#index as HTML
I, [2018-12-04T15:15:24.715114 #3799]  INFO -- : [8b6bdcfa-8079-421b-9dca-d8efcc0b29a3] Completed 401 Unauthorized in 13ms
I, [2018-12-04T15:15:25.309730 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3] Started GET "/users/sign_in" for 179.176.23.59 at 2018-12-04 15:15:25 +0000
I, [2018-12-04T15:15:25.310909 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3] Processing by Devise::SessionsController#new as HTML
I, [2018-12-04T15:15:25.360774 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3]   Rendering devise/sessions/new.html.erb within layouts/devise
I, [2018-12-04T15:15:25.384996 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3]   Rendered devise/shared/_links.html.erb (1.1ms)
I, [2018-12-04T15:15:25.385130 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3]   Rendered devise/sessions/new.html.erb within layouts/devise (24.2ms)
I, [2018-12-04T15:15:25.387651 #3799]  INFO -- : [b9fdd5b8-a3d4-4d62-b283-5abea6eddbc3] Completed 200 OK in 77ms (Views: 29.7ms | ActiveRecord: 15.5ms)
I, [2018-12-04T15:15:39.758968 #3799]  INFO -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba] Started POST "/users/sign_in" for 179.176.23.59 at 2018-12-04 15:15:39 +0000
I, [2018-12-04T15:15:39.759863 #3799]  INFO -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba] Processing by Devise::SessionsController#create as HTML
I, [2018-12-04T15:15:39.759943 #3799]  INFO -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba]   Parameters: {"utf8"=>"✓", "authenticity_token"=>"dJM2PIiOF...VmJKGOA==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
W, [2018-12-04T15:15:39.760715 #3799]  WARN -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba] HTTP Origin header (https://myapp.mydomain.net) didn't match request.base_url (http://myapp.mydomain.net)
D, [2018-12-04T15:15:39.767851 #3799] DEBUG -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba]   User Load (3.6ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "[email protected]"], ["LIMIT", 1]]
I, [2018-12-04T15:15:39.944309 #3799]  INFO -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba] Redirected to http://myapp.mydomain.net/
I, [2018-12-04T15:15:39.944539 #3799]  INFO -- : [5c2e7172-83bc-4cbc-881e-81cb1c7d0eba] Completed 302 Found in 184ms (ActiveRecord: 3.6ms)
I, [2018-12-04T15:15:40.210315 #3799]  INFO -- : [66da50c1-28dd-4488-b6d6-15b487837053] Started GET "/" for 179.176.23.59 at 2018-12-04 15:15:40 +0000
I, [2018-12-04T15:15:40.211170 #3799]  INFO -- : [66da50c1-28dd-4488-b6d6-15b487837053] Processing by DashboardController#index as HTML
I, [2018-12-04T15:15:40.212251 #3799]  INFO -- : [66da50c1-28dd-4488-b6d6-15b487837053] Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
I, [2018-12-04T15:15:40.475302 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec] Started GET "/users/sign_in" for 179.176.23.59 at 2018-12-04 15:15:40 +0000
I, [2018-12-04T15:15:40.476543 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec] Processing by Devise::SessionsController#new as HTML
I, [2018-12-04T15:15:40.478899 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec]   Rendering devise/sessions/new.html.erb within layouts/devise
I, [2018-12-04T15:15:40.485069 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec]   Rendered devise/shared/_links.html.erb (0.2ms)
I, [2018-12-04T15:15:40.485198 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec]   Rendered devise/sessions/new.html.erb within layouts/devise (6.2ms)
I, [2018-12-04T15:15:40.485914 #3799]  INFO -- : [f60ec06f-d5ee-429c-906f-38d229b234ec] Completed 200 OK in 9ms (Views: 7.4ms | ActiveRecord: 0.0ms)

These two messages that sadden me:

HTTP Origin header (https://myapp.mydomain.net) didn't match request.base_url (http://myapp.mydomain.net)

Redirected to http://myapp.mydomain.net/

It should be some nonsense in the config of this nginx, but I have no idea.

    
asked by anonymous 04.12.2018 / 16:33

0 answers