|
| Apache2 + SSL の設定方法 (Linuxの場合)
クレッジットカードなどの決済を行いたい場合には、WebサーバーをSSL 対応にする必要があります。
SSL対応 Apache をご利用になりたい方は下記のように設定してください。 インストール手順は下記のようになります。 % cd /usr/local/src % tar zxvf httpd-2.0.54.tar.gz % cd httpd-2.0.54 % ./configure --enable-so --enable-ssl % make % make install SSLの設定に移ります。 % cd /usr/local/apache2/conf そこで2つのディレクトリを作成します。 % mkdir ssl.crt % mkdir ssl.key ●プライベート証明書の作成(第三者機関に頼らず自分で作成する) % cd /usr/local/apache2/conf/ssl.crt % openssl req -new -x509 -nodes -out server.crt -keyout server.key -days 365いくつか質問されますので、答えます。 Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]:Tokyo Locality Name (eg, city) []:Shinagawa-ku Organization Name (eg, company) [Internet Widgits Pty Ltd]:RAT Co.,Ltd. Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:platz.jp Email Address []:メールアドレスを入力同じフォルダに SSL の秘密鍵 server.key とプライベート証明書 server.crt ができます。 server.key はディレクトリ ssl.key に移動させます。 % mv server.key ../ssl.key/ 実行は下記のようにしましょう。 % /usr/local/apache2/bin/httpd -DSSL ●パブリック証明書の作成(第三者認証機関を利用) ■すぐにSSLサーバ証明書が必要な方へ! 1. 疑似乱数の生成 % cd /usr/local/apache2/conf % openssl md5 * > rand.dat2. 秘密鍵ファイル(server.key)の作成 % openssl genrsa -rand rand.dat -des3 1024 > ssl.key/server.key 秘密鍵を保護するためのパスフレーズの入力を求められます。 ここで入力したパスフレーズは後で必要になるので、覚えておいてください。 また、一般ユーザーが見れないように属性を変更します。 % chmod 600 ssl.key/server.key3. CSR の作成 % openssl req -new -key ssl.key/server.key -out csr.pem 秘密鍵のパスフレーズを入力します。 証明書に表示される情報を入力していきます。 (必要なければ単に改行だけ押してください) Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]:Tokyo Locality Name (eg, city) []:Shinagawa-ku Organization Name (eg, company) [Internet Widgits Pty Ltd]:RAT Co.,Ltd. Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:同じフォルダに CSR である csr.pem ができます。 これをベリサインなどに伝えます。 4. サーバーIDの保存 サーバID通知メールを送られてくるので、 「-----BEGIN CERTIFICATE-----」から「-----END CERTIFICATE-----」までを これらの2行も含めて、server.crt のファイル名で保存します。 これを /usr/local/apache2/conf/ssl.crt/ に置いておきます。実行は下記のようにしましょう。 % /usr/local/apache2/bin/httpd -DSSLパスフレーズを聞かれますので、server.key を作成したときに設定した パスフレーズを入力してください。 ○パスフレーズを入力しないで起動する方法 自動起動する場合などは、パスフレーズの入力を外す必要があります。 % cd /usr/local/apache2/conf/ssk.key % openssl rsa -in server.key -out server_nopass.key % chmod 600 server_nopass.key/usr/local/apache2/conf/ssl.conf を1ヶ所変更してください。 SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server_nopass.keyパスフレーズの入力なしで起動することができるようになります。 ●自動起動の設定 (Redhat 9での例) 1. /etc/rc.d/init.d/httpd のファイルを下記のように修正します。 2. % chkconfig --level 3 httpd on を実行する。 /etc/rc.d/init.d/httpd stop /etc/rc.d/init.d/httpd start で起動、終了ができるようになります。SSL対応なしで、Apache を起動 させる場合には、"OPTIONS=-DSSL" の部分をコメントにしてください。
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
##apachectl=/usr/sbin/apachectl
apachectl=/usr/local/apache2/bin/apachectl
##httpd=${HTTPD-/usr/sbin/httpd}
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
OPTIONS=-DSSL
prog=httpd
RETVAL=0
# check for 1.3 configuration
check13 () {
CONFFILE=/etc/httpd/conf/httpd.conf
GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
GONE="${GONE}AccessConfig|ResourceConfig)"
if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
echo
echo 1>&2 " Apache 1.3 configuration directives found"
echo 1>&2 " please read
/usr/share/doc/httpd-2.0.40/migration.html"
failure "Apache 1.3 config directives test"
echo
exit 1
fi
}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
check13 || exit 1
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
## [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /usr/local/apache2/logs/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
check13 || exit 1
killproc $httpd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
## if [ -f /var/run/httpd.pid ] ; then
if [ -f /usr/local/apache2/logs/httpd.pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog
{start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
|
||