如何使用Rails脚本/服务器测试HTTPS?

时间:2009-01-16 18:08:17

标签: ruby-on-rails testing https

我需要在开发中测试与本地Rails脚本/服务器实例的HTTPS连接,但似乎不支持这种连接,而且我无法使用Google-up任何解决方案。

从客户的角度来看,这就是它的样子:

ted@teflon-ted ~/Downloads[master]$ grep tedslaptop /etc/hosts
127.0.0.1   api.tedslaptop.com
ted@teflon-ted ~/Downloads[master]$ /usr/bin/curl https://api.tedslaptop.com:3000/
curl: (35) Unknown SSL protocol error in connection to api.tedslaptop.com:3000 

这就是我在服务器上看到的内容:

$ script/server 
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.5 available at 0.0.0.0:3000
** Use CTRL-C to stop.
Fri Jan 16 13:06:50 -0500 2009: HTTP parse error, malformed request (127.0.0.1): #
Fri Jan 16 13:06:50 -0500 2009: REQUEST DATA: "\200d\001\003\001\000K\000\000\000\020\000\0009\000\0008\000\0005\000\000\026\000\000\023\000\000\n\a\000?\0003\000\0002\000\000/\003\000\200\000\000\005\000\000\004\001\000\200\000\000\025\000\000\022\000\000\t\006\000@\000\000\024\000\000\021\000\000\b\000\000\006\004\000\200\000\000\003\002\000\200xa\377\\?wEM??/\235F\020\232"
---
PARAMS: {}
---

1 个答案:

答案 0 :(得分:14)

HTTPS是在Rails框架之外处理的东西。因此,您无法直接测试它。您的Rails应用程序提供的功能在HTTPS上应与在未加密的HTTP上完全相同。

脚本/服务器使用Mongrel来处理您的请求。 Mongrel不直接支持SSL / HTTPS。

如果您确实要测试HTTPS功能,则必须使用SSL / HTTPS支持(使用mod_ssl)设置Apache(或其他Web服务器),并将其配置为运行Rails应用程序(使用{{1} }或mod_rails)。