我有一个想要部署在SharePoint 2013上的Rails应用程序。
为了实现某种身份验证方式,我需要WEBrick server
为ssl
https
提供服务,并在port
https://localhost:3001
上侦听传入的https。不幸的是,我没有配置服务器的经验。
我只找到了一些旧版Rails的过时教程,它们似乎不再能完成这项工作。
任何建议都是非常感谢的。
发布于 2015-11-20 21:17:13
这是我的解决方案,它与Rails3和4都兼容。
在bin/rails
的顶部添加以下代码
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
ssl_default_options = {
:Port => 443,
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(File.expand_path('../../config/cert/server_development.key', __FILE__)).read),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open(File.expand_path('../../config/cert/server_development.crt', __FILE__)).read),
:SSLCertName => [['CN', WEBrick::Utils::getservername]]
}
ENV['RAILS_SSL'] ? super.merge(ssl_default_options) : super
end
end
end
显然,您需要生成一个自签名证书或购买一个。
然后,当您想要从命令行启动WebRick时,请使用RAILS_SSL=true rails s
。通常,您需要sudo
来侦听端口443,因此您可能需要附加-p 3001
来更改端口。
https://stackoverflow.com/questions/21189920
复制相似问题