运行Ruby1.9.3、Rails 4.2.10并在开发中使用瘦服务器。
我的应用程序在Heroku上使用SSL。需要在本地Mac上运行SSL。
我遵循了这个教程。
https://www.botreetechnologies.com/blog/enable-ssl-for-rails-development-environment-two-minutes
这是我的处理文件:
web: bundle exec rails server thin start -p 3001 -e development --ssl --ssl-verify --ssl-key-file server.key --ssl-cert-file server.crt这是在跟踪中接收到的错误
Invalid request: Invalid HTTP format, parsing fails.
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/request.rb:84:in `execute'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/request.rb:84:in `parse'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/connection.rb:39:in `receive_data'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run_machine'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in `run'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'更新:
虽然我的procfile包含有关cert的信息。我通过这样的终端手动启动瘦rails服务器。
bundle exec rails server thin start -p 3001 -e development所以不确定它是否在使用Procfile?
更新2 ========
尝试使用bundle exec thin start -p 3001 --ssl Had force_ssl设置为false
服务器启动
jn$ bundle exec thin start -p 3001 --ssl
/Users/jn/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/thin-1.6.4/lib/thin/backends/base.rb:103: warning: epoll is not supported on this platform
Using rack adapter
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:3001, CTRL+C to stop尝试按https://localhost:3001,服务器停止时出现错误
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Encryption not available on this event-machine
Abort trap: 6=====更新3:======
尝试过的Puma.io失败了同样的问题(不能建立安全连接)。尝试过的Puma-dev甚至无法识别.dev,URl,尝试手动添加证书和密钥,同样的问题(不能建立安全连接)。
App在http://localhost:3000上加载我们的应用程序登录表单。一旦我登录应用程序,使用http加载正确的用户帐户页面,大约1秒后,页面将被重新分配到相同的用户帐户页面,但是https说‘无法建立安全的连接’。不知道浏览器为什么强迫我使用https吗?应用程序中没有任何东西设置为https,我可以“找到/替换”。
生成了一个新的secret_key,因为它短于20个字符,而不是30个字符。粘贴到secret_key.rb重新启动的服务器。同样的ssl问题。
发布于 2018-11-29 18:00:19
将应用程序更新为2.3.1,这让puma-dev开始工作。删除了抛出错误的config.action_cable.disable_request_forgery_protection = true。
发布于 2018-11-27 04:40:12
您可以使用普马德夫进行本地开发。它使HTTPS的使用没有任何麻烦。
Puma-dev自动通过SSL提供应用程序。当您第一次运行puma-dev时,它可能会导致一个对话框显示在您的密码中。发生的事情是,puma-dev生成自己的CA证书,存储在~/Library/Application Support/io.puma.dev/cert.pem中。
发布于 2018-11-27 03:53:04
更新:基于你最后的评论。您需要用以下两种方法启动本地服务器
foreman start -f Procfile或与
bundle exec thin start -p 3001 --ssl –-ssl-key-file ~/.ssl/localhost.key –-ssl-cert-file ~/.ssl/localhost.crt然而,此配置文件在生产中不起作用。您可能需要在开发中使用备用Procfile-dev文件。
原件:
在Procfile中,请尝试为ssl使用3001端口进行硬编码。
web: bundle exec thin start -p 3001 --ssl –-ssl-key-file ~/.ssl/localhost.key –-ssl-cert-file ~/.ssl/localhost.crt更新2:您应该根本不需要本地dev的证书,您应该可以通过Chrome访问
bundle exec thin start -p 3001 --ssl #this should work without any other arguments然后,您需要将端口传递给浏览器。
https://localhost:3001您也可以尝试在application.rb中注释掉这一点。
#config.force_ssl = true应该只在production.rb中设置
至于你为什么不能安装gem install foreman,我不知道你为什么不能安装,这听起来像是你机器上的某种网络问题,你有防火墙阻塞吗?
https://stackoverflow.com/questions/53492066
复制相似问题