7

RubyデバッガーとSSLをThinで同時に実行する方法を知っている人はいますか?

私はRails 3.0.10でThinをうまく使っています。

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

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

残念ながら、使用時に SSL サポートを使用して Thin を開始する方法が見つかりませんでしたrails server

以下を使用して、SSL サポートを使用して Thin を正常に開始できます。

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

ただし、を使用してデバッガーをアクティブにする方法が見つかりませんでしたthin start

rails serverしたがって、デバッガー ( ) または SSL ( )を実行する選択肢があるようですが、thin start両方を実行することはできません。

rails serverrails/script ファイルを変更することで、Webrick で SSL を実行できるようになるようです (こちらを参照)。私はこのアプローチを試しましたが、成功していません。これが試みの1つです:

#!/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

4 に答える 4

5

開発環境でデバッガーを自分で要求するだけで試すことができます。

Gemfile で:

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

そして、config/environments/development.rb の構成ブロック内で:

require 'ruby-debug'
Debugger.start

これにより、デバッガー ステートメントをコード内の任意の場所に配置できます。

于 2012-01-23T14:12:38.733 に答える
3

これが私の解決策です-開発環境でのみ、ThinTcpServerをハッキングして自己署名SSL証明書をロードしました。私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'
于 2012-07-26T00:57:58.157 に答える
1

Thinを使用して最終的に本番環境で動作するようになった方法は次のとおりです。

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

KEY ファイルに問題がある場合は、次のようなサイトを使用して CSR を検証してください。

https://ssl-tools.verisign.com

CSR が失敗すると、署名機関から受け取る証明書も失敗します。私のサイトは SSL 証明書の読み込みを拒否し、秘密鍵の作成中に州名を「Texas」ではなく「TX」に省略したことがわかりました。それがずっと機能していなかった理由でした!SSL証明書はお尻の痛みです!

于 2013-08-06T18:02:59.397 に答える