简体   繁体   English

Ruby on Rails Thin和force_ssl,通过HTTP的空响应

[英]Ruby on Rails Thin and force_ssl, empty response over HTTP

I've set up several Ruby on Rails servers lately on CentOS 7.x using Thin as the web server and an SSL Certificate from Comodo. 我最近在CentOS 7.x上使用Thin作为Web服务器以及Comodo的SSL证书在CentOS 7.x上设置了多个Ruby on Rails服务器。

I have enabled the force_ssl option in my config/environments/production.rb file, and I'm running my server with the command: 我已经在config/environments/production.rb文件中启用了force_ssl选项,并且正在使用以下命令运行服务器:

RAILS_ENV=production thin start -a <IP> -p 3000 --ssl --ssl-key-file <KEY FILE PATH> --ssl-cert-file <CERT FILE PATH>

I'm using devise, so in config/initializers/devise.rb I set 我正在使用config/initializers/devise.rb ,因此在config/initializers/devise.rb设置

config.rememberable_options = { secure: true }

I also set some config in config/initializers/session_store.rb 我还在config/initializers/session_store.rb设置了一些配置

Rails.application.config.session_store :cookie_store, key: '_secure_<domain>_session', httponly: true, secure: true

When I first access my server over HTTP from an internet browser I get an empty response message (tested with multiple browsers and multiple computers). 当我第一次从Internet浏览器通过HTTP访问服务器时,我收到一条空响应消息(已在多个浏览器和多台计算机上进行了测试)。 When I access it over https directly it resolves fine (and SSL is working perfectly), and when I next try to access over http it redirects just fine. 当我直接通过https访问它时,它可以很好地解析(并且SSL运行正常),而当我下次尝试通过http访问时,它可以重定向。 I'm not certain what I can do to fix this bar using nginx or Apache. 我不确定如何使用nginx或Apache修复此栏。

Here are the other questions I've read: 这是我读过的其他问题:

Thin can only listen on one port and can only serve either SSL or non-SSL requests per instance. Thin只能在一个端口上侦听,并且每个实例只能服务SSL或非SSL请求。 When thin is started with --ssl it attempts to process inbound connections as TLS connections, and will drop those which it can't negotiate (ie, plain HTTP requests). 当使用--ssl启动Thin时,它将尝试将入站连接处理为TLS连接,并将其无法协商的那些连接(即纯HTTP请求)丢弃。

You need to use nginx (or some other reverse proxy) to listen on multiple ports and terminate SSL, and then forward to Thin. 您需要使用nginx(或其他反向代理)来侦听多个端口并终止SSL,然后转发到Thin。 Otherwise, you'll need to run multiple Thin instances, one serving SSL and the other not. 否则,您将需要运行多个Thin实例,一个实例提供SSL,而另一个实例则不提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM