玄箱HGメモ / Debian / Apache2+SSL対応


Last update: 2009-05-14 (木) 15:17:09
実施: 2009/02/10

玄箱HGメモ/Debian/Apache2+SSL対応

緑文字が入力コマンド。


Debian Apache2 SSL対応

HTTPサーバーのApache2をSSL対応にします。
管理者権限(管理者アカウント参照)で作業する必要があります。

etch化したDebianではスクリプトapache2-ssl-certificateは使えないとのこと。
代わりにmake-ssl-certというスクリプトを使います。

Apache2 common/doc導入

KAGUYA:~# aptitude install apache2-common apache2-doc[ENTER]

Apache2 common/doc導入画面(例)

SSL導入

KAGUYA:~# aptitude install ssl-cert[ENTER]

ssl-cert導入画面(例)

SSL設定

SSL設定スクリプト編集

/usr/sbin/make-ssl-cert/usr/sbin/apache2-ssl-certにコピーしてこれを編集します。

自己署名なので、1年ぐらいで作ります。
そのための編集です。

KAGUYA:~# cp -p /usr/sbin/make-ssl-cert /usr/sbin/apache2-ssl-cert[ENTER]
KAGUYA:~# vi /usr/sbin/apache2-ssl-cert[ENTER]

/usr/sbin/apache2-ssl-certの例(抜粋)


#!/bin/bash -e
# This is a mockup of a script to produce a snakeoil cert
# The aim is to have a debconfisable ssl-certificate script

  :  (省略)

# create the certiface.

export RANDFILE=/dev/random

if [ "$1" != "generate-default-snakeoil" ]; then

以下の行に-days 365を追加

    openssl req -config $TMPFILE -new -x509 -nodes -out $output -keyout $output > /dev/null 2>&1


    openssl req -config $TMPFILE -new -days 365 -x509 -nodes -out $output -keyout $output > /dev/null 2>&1
    chmod 600 $output
    # hash symlink
    cd $(dirname $output)
    ln -sf $(basename $output) $(openssl x509 -hash -noout -in $output)
else

  :  (省略)

# cleanup
rm -f $TMPFILE~

/usr/sbin/apache2-ssl-cert編集画面(例)


SSL設定スクリプト実行

/usr/sbin/apache2-ssl-certを実行します。

KAGUYA:~# mkdir /etc/apache2/ssl[ENTER]
KAGUYA:~# /usr/sbin/apache2-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem[ENTER]

/usr/sbin/apache2-ssl-cert実行画面(例)

各質問には以下の例のように入力します。

  • Country Name(国名): JP ←日本の場合はJP固定
  • State or Province Name(都道府県名): Hyogo ←適当
  • Locality Name(市区町村名): Amagasaki ←適当
  • Organisation Name(組織名): Beauty Blanch System Club ←適当
  • Organisational Unit Name(部署名): System Unit ←適当
  • Host Name(ホスト名): KAGUYA ←本来はドメイン名
  • Email Address(メールアドレス): kanae@bbs.co.jp ←管理者のメールアドレス

Apache2 SSL設定

/usr/share/doc/apache2.2-common/examples/apache2/extra/httpd-ssl.conf.gzに含まれるhttpd-ssl.conf/etc/apache2/sites-available/sslにコピーしてこれを編集します。

KAGUYA:~# cd /etc/apache2/sites-available[ENTER]
KAGUYA:~# cp -p /usr/share/doc/apache2.2-common/examples/apache2/extra/httpd-ssl.conf.gz .[ENTER]
KAGUYA:~# gzip -d httpd-ssl.conf.gz[ENTER]
KAGUYA:~# cp -p httpd-ssl.conf ssl[ENTER]
KAGUYA:~# vi /etc/apache2/sites-available/ssl[ENTER]

/etc/apache2/sites-available/sslの例(抜粋)


  :  (省略)

##
## SSL Virtual Host Context
##

以下の1行を#でコメントアウトして2行を追加

<VirtualHost _default_:443>


# <VirtualHost _default_:443>
NameVirtualHost *:443
<VirtualHost *:443>
#   General setup for the virtual host

以下の3行を#でコメントアウトして3行を追加

DocumentRoot "/usr/share/apache2/default-site/htdocs"
ServerName www.example.com:443
ServerAdmin you@example.com


# DocumentRoot "/usr/share/apache2/default-site/htdocs"
# ServerName www.example.com:443
# ServerAdmin you@example.com
DocumentRoot "/var/www"
ServerName KAGUYA:443
ServerAdmin kanae@bbs.co.jp
ErrorLog /var/log/apache2/error_log
TransferLog /var/log/apache2/access_log

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Cipher Suite:
#   List the ciphers that the client is permitted to negotiate.
#   See the mod_ssl documentation for a complete list.
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

#   Server Certificate:
#   Point SSLCertificateFile at a PEM encoded certificate.  If
#   the certificate is encrypted, then you will be prompted for a
#   pass phrase.  Note that a kill -HUP will prompt again.  Keep
#   in mind that if you have both an RSA and a DSA certificate you
#   can configure both in parallel (to also allow the use of DSA
#   ciphers, etc.)

以下の1行を#でコメントアウトして1行を追加

SSLCertificateFile /etc/apache2/server.crt


# SSLCertificateFile /etc/apache2/server.crt
SSLCertificateFile /etc/apache2/ssl/apache.pem
#SSLCertificateFile /etc/apache2/server-dsa.crt

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)

以下の1行を#でコメントアウトして1行を追加

SSLCertificateKeyFile /etc/apache2/server.key


# SSLCertificateKeyFile /etc/apache2/server.key
SSLCertificateKeyFile /etc/apache2/ssl/apache.pem
#SSLCertificateKeyFile /etc/apache2/server-dsa.key

#   Server Certificate Chain:

  :  (省略)


/etc/apache2/sites-available/ssl編集画面(例)

Apache2 default設定

/etc/apache2/sites-available/defaultを編集します。

2009/02/13追記

/etc/apache2/sites-available/defaultを直接操作するのは嫌がられているみたいなので、/etc/apache2/sites-available/defにコピーしてこれを編集します。
KAGUYA:~# cp -p /etc/apache2/sites-available/default /etc/apache2/sites-available/def[ENTER]

defaultを無効にしてdefを有効にします。 KAGUYA:~# a2dissite default[ENTER]
KAGUYA:~# a2ensite def[ENTER]

以降のページではdefaultdefに読み換えてください。

KAGUYA:~# vi /etc/apache2/sites-available/default[ENTER]

/etc/apache2/sites-available/defaultの例(抜粋)


以下の3行を#でコメントアウトして4行を追加

NameVirtualHost *
<VirtualHost *>
	ServerAdmin webmaster@localhost


# NameVirtualHost *
# <VirtualHost *>
# 	ServerAdmin webmaster@localhost
NameVirtualHost *:80
<VirtualHost *:80>
ServerName KAGUYA:80
	ServerAdmin piroshiki_man10@yahoo.co.jp
    
    DocumentRoot /var/www/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

  :  (省略)


/etc/apache2/sites-available/default編集画面(例)

SSL有効化

KAGUYA:~# a2enmod ssl[ENTER]

a2enmod ssl画面(例)

Module ssl installed; run /etc/init.d/apache2 force-reload to enable.

KAGUYA:~# a2ensite ssl[ENTER]

a2ensite ssl画面(例)

Site ssl installed; run /etc/init.d/apache2 reload to enable.

Apach2再起動

KAGUYA:~# /etc/init.d/apache2 restart[ENTER]

Apach2再起動画面(例)

Forcing reload of web server (apache2)...Warning: DocumentRoot [/usr/share/apache2/default-site/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.100.100 for ServerName
 waiting Warning: DocumentRoot [/usr/share/apache2/default-site/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.100.100 for ServerName

何かエラーが出てるので玄箱/HGをリブートします。

2009/02/12追記

Warning: DocumentRoot? [/usr/share/apache2/default-site/htdocs] does not exist

/etc/apache2/sites-available/sslに以下の1行を追加しています。

DocumentRoot "/var/www"

Apache2+SSL接続確認

HTTP+SSL接続

ブラウザで
https://KAGUYA
のように玄箱/HGを表示します。

ホスト名がだめなら/etc/hostsで指定したIPアドレスで接続します。

Apache2+SSLで接続できることを確認しました。


コメント

コメントはありません。 コメント/玄箱HGメモ/Debian/Apache2+SSL対応?

Online: 1


FrontPage

Soft

Tips


最新の20件

2021-12-21 2020-04-06 2020-03-10 2013-06-28 2013-11-13 2014-06-24

今日の20件

  • counter: 1836
  • today: 1
  • yesterday: 0
  • online: 1

edit