玄箱HGメモ/Debian/Apache2+SSL対応
緑文字が入力コマンド。
HTTPサーバーのApache2をSSL対応にします。
管理者権限(管理者アカウント参照)で作業する必要があります。
etch化したDebianではスクリプトapache2-ssl-certificateは使えないとのこと。
代わりにmake-ssl-certというスクリプトを使います。
KAGUYA:~# aptitude install apache2-common apache2-doc[ENTER]
KAGUYA:~# aptitude install ssl-cert[ENTER]
/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編集画面(例)
/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実行画面(例)
各質問には以下の例のように入力します。
/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編集画面(例)
/etc/apache2/sites-available/defaultを編集します。
/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]
以降のページではdefaultをdefに読み換えてください。
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編集画面(例)
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.
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をリブートします。
Warning: DocumentRoot? [/usr/share/apache2/default-site/htdocs] does not exist
/etc/apache2/sites-available/sslに以下の1行を追加しています。
DocumentRoot "/var/www"
ブラウザで
https://KAGUYA
のように玄箱/HGを表示します。
ホスト名がだめなら/etc/hostsで指定したIPアドレスで接続します。
Apache2+SSLで接続できることを確認しました。
コメントはありません。 コメント/玄箱HGメモ/Debian/Apache2+SSL対応?
Online: 1