2012-01-06 15 views
7

Thinを使用して同時にルビデバッガとSSLを実行する方法を知っている人はいますか?SSLサポートとルビーデバッグを使用したシンビット

私はRails 3.0.10でThinをうまく使ってきました。

rails server --debuggerを使用して起動し、コードをデバッグできます。

最近、アプリケーションにSSLサポートを追加する必要があり、ローカルで自己署名証明書でテストできるようにしたいと考えています。

残念ながら、rails serverを使用してSSLサポートを使用してThinを開始する方法が見つかりませんでした。私が正常に使用してSSLをサポートしてシンを起動することができ

thin start --ssl --ssl-verify --ssl-key-file ssllocal/server.key 
    --ssl-cert-file ssllocal/server.crt 

はしかし、私はthin startを使用してデバッガを有効にする方法を発見していません。

私はデバッガ(rails server)またはSSL(thin start)を実行する選択肢があるようですが、その両方ではないようです。

WEBrickには、レール/スクリプトファイル(see here)を変更することによって、rails serverを使用してSSLを実行するために得ることが可能と思われます。私はこのアプローチを実験しましたが、私は成功しませんでした。

#!/usr/bin/env ruby 
# This command will automatically be run when you run "rails" with Rails 3 
# gems installed from the root of your application. 

APP_PATH = File.expand_path('../../config/application', __FILE__) 
require File.expand_path('../../config/boot', __FILE__) 


# THIS IS NEW: 
require "rails/commands/server" 
require 'rack' 
require 'thin' 
module Rails 
    class Server 
    def default_options 
     super.merge({ 
     :Port  => 3000, 
     :environment => (ENV['RAILS_ENV'] || "development").dup, 
     :daemonize => false, 
     :debugger => false, 
     :pid   => File.expand_path("tmp/pids/server.pid"), 
     :config  => File.expand_path("config.ru"), 
     :SSLEnable => true 
     :ssl => true, 
     "ssl-verify" => true, 
     "ssl-key-file" => File.expand_path("ssllocal/server.key"), 
     "ssl-cert-file" => File.expand_path("ssllocal/server.crt")  
     }) 
    end 
    end 
end 


require 'rails/commands' 

注:ここでの試みの一つだ不思議に思われるかもしれない人のために、私は自分のルートアプリケーションディレクトリオフ「ssllocal」ディレクトリを作成し、私はSSLキーと本命の格納場所というのです。

答えて

4

開発環境では、デバッガだけを必要とするようにできます。あなたのGemfileに

if RUBY_VERSION =~ /^1.9/ 
    gem "ruby-debug19", :group => :development 
else 
    gem "ruby-debug", :group => :development 
end 

そして、あなたのconfig /環境/ development.rbのconfigブロック内:

require 'ruby-debug' 
Debugger.start 

これはどこでもあなたのコード内のデバッガステートメントを配置することを許可します。

3

私の解決策は - 開発環境でのみ自己署名入りのSSL証明書を読み込むためにThin TcpServerをハックしました。私script/railsは、次のようになります。

#!/usr/bin/env ruby 
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 

APP_PATH = File.expand_path('../../config/application', __FILE__) 
require File.expand_path('../../config/boot', __FILE__) 

# Hack our SSL certs into Thin TcpServer, only in development environment 
require 'thin' 
module Thin 
    module Backends 
    TcpServer.class_eval do 
     def initialize_with_SSL(host, port) 
     if Rails.env.development? 
      Rails.logger.info "Loading SSL certs from ./ssl_dev..." 
      @ssl = true 
      @ssl_options = { 
      :private_key_file => File.expand_path("../../ssl_dev/server.key", __FILE__), 
      :cert_chain_file => File.expand_path("../../ssl_dev/server.crt", __FILE__), 
      :verify_peer => nil 
      } 
     end 

     initialize_without_SSL(host, port) 
     end 

     alias_method :initialize_without_SSL, :initialize 
     alias_method :initialize, :initialize_with_SSL  
    end 
    end 
end 

# Must load 'rails/commands' after Thin SSL hack 
require 'rails/commands' 
0

私が正常にネイサンによって提案されたソリューションを使用して、薄いSSLを有効にした状態で作業デバッグを取得することができました。私はinitialize_without_sslのコール(オリジナルtcpserverののinitializeの別名方法)上記のコードsnippettで

require 'thin' 
module Thin 
    module Backends 
    TcpServer.class_eval do 
     def initialize_with_SSL(host, port) 
     if Rails.env.development? 
      Rails.logger.info "Loading SSL certs from ./ssl_dev..." 
      @ssl_options = { 
      :private_key_file => File.expand_path("../../ssl_dev/server.key", __FILE__), 
      :cert_chain_file => File.expand_path("../../ssl_dev/server.crt", __FILE__), 
      :verify_peer => nil 
      } 
     end 

     initialize_without_SSL(host, port) 
     # @ssl initialized after calling the original initialize of TcpServer 
     @ssl = true if Rails.env.development? 

     end 

     alias_method :initialize_without_SSL, :initialize 
     alias_method :initialize, :initialize_with_SSL  
    end 
    end 
end 

    alias_method :initialize_without_SSL, :initialize 
    alias_method :initialize, :initialize_with_SSL  
end 

後@sslの初期化を延期する一つの小さな変更をしなければならなかったものの、@sslを呼び出した後にtrueに設定されています元のThin :: Backend :: TcpServerの初期化コール。ネイサンのコードブロックで述べたようにゼロ

#Base initialize method. Thin gem version 1.5.0 
    def initialize 
    @connections     = [] 
    @timeout      = Server::DEFAULT_TIMEOUT 
    @persistent_connection_count = 0 
    @maximum_connections   = Server::DEFAULT_MAXIMUM_CONNECTIONS 
    @maximum_persistent_connections = Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS 
    @no_epoll      = false 
    @ssl       = nil 
    @threaded      = nil 
    end 

に@sslを設定し、ソリューション全体の周りハックであると表示されます。tcpserverの親のinitialize(基本シン::バックエンド)が起動しますので、私はこれをしなければなりませんでした。私の意見では、コードはenv.developmentのコンテキスト内で実行されていると考えています。最も重要なことは、sslを有効にしてデバッグできることです。

0

ここで私はそれが最終的にシンを使用して生産に取り組むようになった方法は次のとおりです。あなたはあなたのKEYファイルに問題がある場合は

rvmsudo thin start -p 443 --ssl --ssl-key-file ssl/server.key --ssl-cert-file ssl/server.crt 

、あなたのようなサイトを使用してCSRを検証していることを確認します

https://ssl-tools.verisign.com 

CSRが失敗すると、署名当局から受け取った証明書も失敗します。 私のサイトではSSL証明書の読み込みを拒否し、私の秘密鍵を作成する際に私の州名を「テキサス」ではなく「TX」に短縮していることを確認するだけです。それは、それがすべて一緒に働いていなかった理由でした! SSL証明書はお尻の痛みです!

関連する問題