1

我正在使用 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 选项。

4

2 回答 2

1

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

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

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

于 2013-03-25T13:41:10.477 回答
0

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

于 2013-03-22T17:56:08.603 回答