简体   繁体   English

本地主机上的SSL Webrick未在Rails应用程序上托管ruby

[英]SSL Webrick on localhost not hosting ruby on rails app

How do I get Ruby On Rails Webrick to work with self-signed SSL certificate on localhost just to test https ? 如何使Ruby On Rails Webrick可以在本地主机上使用自签名SSL证书来测试https? Basically, Ived followed the work that has been done here: Configure WEBrick to use automatically generated self-signed SSL/HTTPS certificate 基本上,Ived遵循此处完成的工作:将WEBrick配置为使用自动生成的自签名SSL / HTTPS证书

And produce the script like the following: 并生成如下所示的脚本:

require 'webrick'
require 'webrick/https'

cert_name = [
  %w[CN localhost],
]

server = WEBrick::HTTPServer.new(:Port => 8000,
                                 :SSLEnable => true,
                                 :SSLCertName => cert_name)


# Shutdown gracefully on signal interrupt CTRL-C
# http://www.ruby-doc.org/core-2.1.1/Kernel.html#method-i-trap
trap('INT') { server.shutdown }

server.start

When I tried to access https://localhost:8000/ , it did warn about trust but just went ahead, instead I had nothing come out but this. 当我尝试访问https:// localhost:8000 /时 ,它确实警告了信任,但只是继续前进,相反,我什么也没出来。 BTW, https works fine, just it seems its not getting the right route for SSL. 顺便说一句,https工作正常,只是看起来它没有获得正确的SSL路由。

Not Found

`/' not found.
WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08) OpenSSL/1.0.2 at localhost:8000

console prints this: 控制台打印此:

[2015-07-25 23:38:25] INFO  WEBrick::HTTPServer#start: pid=6765 port=8000
[2015-07-25 23:38:32] ERROR `/' not found.
localhost - - [25/Jul/2015:23:38:32 MYT] "GET / HTTP/1.1" 404 284
- -> /

The reason your server is returning that 404 is because the script you've set up is just for an empty WEBrick server; 您的服务器返回404的原因是因为您设置的脚本仅用于空的WEBrick服务器。 it doesn't actually mount your Rails app. 它实际上并没有挂载您的Rails应用程序。 The thread you linked to seemed to be using that script just as a minimal test for the SSL functionality. 您链接到的线程似乎正在使用该脚本,作为对SSL功能的最小测试。 The full answer to getting WEBrick to work with SSL looks to be answered here: How do you configure WEBrick to use SSL in Rails? 使WEBrick与SSL配合使用的完整答案似乎在这里得到回答: 如何配置WEBrick在Rails中使用SSL?

However, I wouldn't recommend you bother. 但是,我不建议您打扰。 WEBrick is strictly meant as a development-only server, and isn't suitable for use in production (which is why it's hard to get it to do things like use SSL). WEBrick严格意义上来说是仅用于开发的服务器,不适合在生产环境中使用(这就是为什么很难让它执行诸如使用SSL之类的事情)。 Instead, either set up nginx as a SSL-serving proxy to your app or use a server which supports SSL easily, like thin does . 相反,要么将nginx设置为应用程序的SSL服务代理,要么使用如Thin一样轻松支持SSL的服务器。

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

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