Rails 5,Nginx,Puma,Rails管理员 - ERR_TOO_MANY_REDIRECTS

问题描述 投票:0回答:1

我想知道如何在rails 5 app中强制执行SSL。该应用程序在开发中运行良好。在生产中,通过rails admin通过SSL的一些POST请求不起作用。

如果通过production.rb强制执行SSL,则浏览器返回:

"ERR_TOO_MANY_REDIRECTS"

如果“force_ssl”设置为false,则通过rails admin返回一些“POST”请求:

HTTP Origin header (https://www.example.com) didn't match request.base_url (http://www.example.com)

提前致谢。

这些是应用程序设置:

production.rb

  # ...
  config.force_ssl = true
  # ...

nginx.conf

upstream puma {
  server unix:///home/bgc/apps/domain/shared/tmp/sockets/domain-puma.sock;
}

server {
  listen 80;
  listen 443 ssl;
  server_name domain.com;

  ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/domain.com/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 
  ssl_protocols TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;


  root /home/bgc/apps/domain/current/public;
  access_log /home/bgc/apps/domain/current/log/nginx.access.log;
  error_log /home/bgc/apps/domain/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-Proto https;
    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;
}
ruby-on-rails nginx puma rails-admin
1个回答
0
投票

原因很简单。当您使用带有ssl的Nginx服务器时,它已经为您排序了ssl。如果从production.rb中删除config.force_ssl = true,它将被排序。

© www.soinside.com 2019 - 2024. All rights reserved.