Friday, November 9, 2012

redmineとjenkinsの仕込み #4(SSL化編)


18. mod_sslのインストール

  • rootになる
  • mod_sslをインストール
#yum -y install mod_ssl

19. オレオレ証明書を作る 

  • 証明書の有効期限を長くする
/etc/pki/tls/certs/Makefileに "-days 365" ってのが3カ所あるので書き換える
  • 証明書を作る 
# make server.crt
umask 77 ; \
        /usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 bit long modulus
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
umask 77 ; \
        /usr/bin/openssl req -utf8 -new -key server.key -x509 -days 3650 -out server.crt -set_serial 0
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Aichi
Locality Name (eg, city) [Default City]:Nagoya
Organization Name (eg, company) [Default Company Ltd]:ONE STEP BEYOND
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:ホスト名
Email Address []:メールアドレス
  • apache起動時にパスワードを要求されないようにサーバー用秘密鍵からパスワード削除
# openssl rsa -in server.key -out server.key

20. apacheの設定 

  • ssl用のDocumentRootを作る
/var/www/secure としてみた
# mkdir /var/www/secure
  • redmineのシンボリックリンクこっちに張る
# ln -s /usr/local/redmine-2.0.4/public /var/www/secure/redmine
  • 元のシンボリックリンクを消す 
# rm /var/www/html/redmine
  • 設定ファイル /etc/httpd/conf.d/ssl.conf はサンプルをベースに、以下の3カ所を編集
DocumentRoot "/var/www/secure/html"
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/certs/server.key
  • jenkinsの設定をSSLの方に引っ越す 
  • オーナーをapacheに
# chown -R apache:apache /var/www/secure 
  • apche再起動
# /etc/init.d/httpd restart
  • EC2のSecurityGroupでHTTPSを開ける
  • httpsでアクセスできるかテスト
  • /redmineと/jenkinsはhttpでアクセスがあったらhttpsに飛ばす設定にする
/etc/httpd/conf.d/rewire.conf を以下の内容で作成
<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteLog "logs/rewrite_log"
      RewriteLogLevel 0
      RewriteCond %{SERVER_PORT} !^443$
      RewriteRule ^/redmine https://%{HTTP_HOST}/redmine [L,R]
      RewriteRule ^/jenkins https://%{HTTP_HOST}/jenkins [L,R]
  • apache再起動
# /etc/init.d/httpd restart
  •  ちゃんとrewriteされるかをテスト

No comments:

Post a Comment