LoginSignup
0
0

Windows 環境の Puma(Rails7のデフォルトWebサーバ) でhttps接続する

Posted at

OpenSSLのセットアップ

  1. PumaのSSL対応を確認する。設定していないので、falseである。

    ruby -rpuma -e "puts Puma.ssl?"
    
  2. 管理者権限でコマンドプロンプトを起動して、OpenSSLをインストールする。「インストールを行いますか?」に[Y]で答える。

    ridk exec pacman -S mingw-w64-x86_64-openssl
    
  3. OpenSSLをインストールしたので、Pumaを再インストールする。今度は true が返る。

    gem uninstall puma
    bundle install
    ruby -rpuma -e "puts Puma.ssl?"
    

秘密鍵と自己証明書の作成

  • コマンドプロンプトで以下を実行し、自己証明書を作成する。カレントフォルダにキーと証明書が作成される。
    ridk exec openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -days 365 > server.crt
    

Pumaの設定と起動

  1. Pumaの設定ファイルを修正する。ここではキーと証明書をSSLフォルダに置いた。
    config/puma.rb
    ssl_bind '0.0.0.0', '9292', {
      key: 'ssl/server.key',
      cert: 'ssl/server.crt'
    }
    
  2. rails sで起動して、 ブラウザで「https://localhost:9292」にアクセスする。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0