【问题标题】:Ruby on rails app working on http but not on httpsRuby on rails 应用程序在 http 上工作,但不在 https 上
【发布时间】:2018-07-26 14:50:05
【问题描述】:

我有一个在 Nginx 中运行的 RoR 应用程序。我使用 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_OUTerror。有人可以帮助我吗?

【问题讨论】:

  • 为什么listen 443 ssl这行注释掉了? HTTPS 默认使用 443 端口,所以如果 nginx 没有监听该端口,浏览器将无法连接。
  • 这对我来说似乎不是一个 RoR 问题。也许你应该删除标签?
  • 对不起@JackBracken,我更改了配置,忘记取消注释listen 443 sslcode。我删除了rails标签@jvillian上的ruby。谢谢
  • 你解决了吗?
  • 是的,@BerkhanBerkdemir。我认为问题出在 ssl 证书链上。我没有很好地创建它。

标签: nginx capistrano puma


【解决方案1】:

解决方案:

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 证书链。它没有很好地创建。

【讨论】:

    猜你喜欢
    • 2012-07-17
    • 2015-11-19
    • 2013-08-18
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多