Ruby rails 应用在 http 上工作但不在 https 上

Ruby on rails app working on http but not on https

我在 Nginx 中有一个 RoR 应用 运行ning。我使用 capistrano 和 puma 将应用程序部署到服务器。它在这个 nginx 配置下运行良好:

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

server {
  listen 80;
  keepalive_timeout   70;
  server_name kiuiapp.com;

  root /home/kiui/apps/kiui/current/public;
  access_log /home/kiui/apps/kiui/current/log/nginx.access.log;
  error_log /home/kiui/apps/kiui/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-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
}

但我需要 运行 具有 https 的 rails 应用程序才能在其中使用 Facebook 应用程序。我按照本教程 create autosigned ssl certificate 创建了一个自动签名的 ssl 证书,并将 nginx 配置更改为:

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

server {
  listen 443 ssl;
  keepalive_timeout   70;
  server_name kiuiapp.com;

  ssl on;
  ssl_certificate /etc/ssl/kiui.crt;
  ssl_certificate_key /etc/ssl/kiui.key;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 10m;

  root /home/kiui/apps/kiui/current/public;
  access_log /home/kiui/apps/kiui/current/log/nginx.access.log;
  error_log /home/kiui/apps/kiui/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-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
}

没用!浏览器给我 ERR_CONNECTION_TIMED_OUT 错误。有人可以帮助我吗?

解决方案:

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

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  keepalive_timeout   70;
  server_name kiuiapp.com;
  ssl on;
  ssl_certificate /root/kiuiapp.com.chain.cer;
  ssl_certificate_key /root/kiuiapp.com.key;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 10m;

  root /home/kiui/apps/kiui/current/public;
  access_log /home/kiui/apps/kiui/current/log/nginx.access.log;
  error_log /home/kiui/apps/kiui/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-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
}

我认为问题出在 ssl 证书链上。制作的不是很好