【问题标题】:No data received when running "thin start"运行“精简启动”时未收到数据
【发布时间】:2013-03-22 14:29:16
【问题描述】:

我正在使用 ruby​​ 1.9.3 和 rvm。我想使用 --ssl 选项运行瘦服务器。我在一些答案中读到运行“thin start --ssl”应该可以解决问题。 但是在我的开发环境中,当我运行 thin start --ssl 时,终端会运行:

Using rack adapter
Thin web server (v1.5.1 codename Straight Razor)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
And in my web-browser in localhost:3000:

No data received
Unable to load the webpage because the server sent no data.
Here are some suggestions:
Reload this webpage later.
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

当我使用“rails s thin”运行相同的命令时,它可以工作,但会显示不同的消息:

Booting Thin
Rails 3.2.11 application starting in development on http:// 0. 0. 0 .0 :3000
Call with -d to detach
Ctrl-C to shutdown server

我不知道为什么会发生这种情况(可能是因为 rvm),但 Thin 工作正常。我想运行第一个版本“thin start --ssl”,因为我无法在“rails s”命令中设置这个 ssl 选项。

【问题讨论】:

  • 您的浏览器返回什么状态码?我想知道是否是因为您没有为 Thin 设置 SSL 证书?你设置过类似的东西吗?
  • 好吧,我尝试运行一个瘦的 Rails 服务器,并按照stackoverflow.com/questions/3604303/… 中的建议传递 SSL 证书。但是,我收到状态代码“错误 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL 协议错误。”

标签: ruby-on-rails ssl thin


【解决方案1】:

我找到了“未收到数据”的原因。如果有人有同样的错误:

我运行了“thin start --ssl”,所以我的服务器只会响应 https 请求。所有的http请求都没有得到回应,所以这就是没有数据的原因(愚蠢)。默认情况下,http 请求转到 80 端口,而 https 请求转到 443 端口。

“thin start --ssl”可以很好地在本地调试 ssl,您可以通过在应用程序控制器中强制使用 ssl 来测试整个应用程序(这样您就不会发现自己处于同样的情况,没有收到任何数据)。

【讨论】:

    【解决方案2】:

    一个更简单(也更真实)的解决方案是在您的 Rails 应用程序前面运行一个 Web 服务器(如 nginx)。此 Web 服务器将侦听 http 和 https 流量,然后将所有内容通过端口 3000 传递给 Rails(瘦)服务器。

    【讨论】:

    • 我想在本地设置 SSL,认为这比首先配置我的生产服务器和安装 nginx 和乘客更容易。我不知道我的应用程序中的问题是由于服务器中的 SSL 配置还是应用程序中的其他一些 ssl_requirement 文件造成的。
    • 如何设置这个服务器?我已经在我的 ubuntu 上安装了乘客和 nginx,但我仍然不知道如何将它们配置为在本地工作。
    • 这里是一个示例配置的链接。您真正要做的就是让 nginx 在 80/433 上侦听,然后将两个侦听器指向同一个 Rails 应用程序:candidcode.com/2009/09/12/…
    猜你喜欢
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多