#/usr/local/apache2/bin/apachectl stop /usr/local# mv apache2/ apache2.05_webdav/
(2004/09現在最新版のopensslは0,9.7d。あらかじめ /usr/local/src/ に置いてある) /usr/local/src# tar zxvf openssl-0.9.7d.tar.gz /usr/local/src# cd openssl-0.9.7d /usr/local/src/openssl-0.9.7d# ./config -fPIC shared /usr/local/src/openssl-0.9.7d# make /usr/local/src/openssl-0.9.7d# make install/etc/ld.so.confを編集して、インストールしたopensslのライブラリにパスを通す。
# vi /etc/ld.so.conf 【以下を追加】 /usr/local/ssl/lib/etc/ld.so.confを修正後、ldconfigコマンドを実行。
# ldconfig
# cd /usr/local/src /usr/local/src# tar zxvf httpd-2.0.51.tar.gz /usr/local/src# cd httpd-2.0.51 /usr/local/src/httpd-2.0.51# ./configure --enable-so --enable-dav=yes --enable-ssl --enable-auth-digest --prefix=/usr/local/apache2.0.51 (1行で) /usr/local/src/httpd-2.0.51# make /usr/local/src/httpd-2.0.51# make install /usr/local/src/httpd-2.0.51# ln -s /usr/local/apache2.0.51 /usr/local/apache2最後に"mod_so.c"、"mod_ssl.c"と "mod_dav.c"ならびに"mod_dav_fs.c"があるか確認する。
# /usr/local/apach2/bin/httpd -l Compiled in modules: core.c mod_access.c mod_auth.c mod_auth_digest.c ←ダイジェスト認証 mod_include.c mod_log_config.c mod_env.c mod_setenvif.c mod_ssl.c ←ssl接続 prefork.c http_core.c mod_mime.c mod_dav.c ←WebDAV mod_status.c mod_autoindex.c mod_asis.c mod_cgi.c mod_dav_fs.c ←WebDAV mod_negotiation.c mod_dir.c mod_imap.c mod_actions.c mod_userdir.c mod_alias.c mod_so.cあるようだ。
(L.546あたり) #ServerTokens Full ServerTokens Prod ServerSignature Off確認。
【確認】/usr/local/apache2/conf/httpd.conf
・・・・・【略】・・・・・
< IfModule mod_ssl.c>
Include conf/ssl.conf
< /IfModule>
・・・・・【略】・・・・・
まずは、秘密鍵を作成するんだそうだ。 格納するディレクトリは /usr/local/apache2/conf/ssl.key/ だ。
# mkdir /usr/local/apache2.0.51/conf/ssl.key # cd /usr/local/apache2.0.51/conf/ssl.key/ /usr/local/apache2.0.51/conf/ssl.key # /usr/local/ssl/bin/openssl genrsa -des3 -out server.key 1024 (1行で) Generating RSA private key, 1024 bit long modulus ...............++++++ .....................++++++ e is 65537 (0x10001) Enter pass phrase for server.key: ←ssl専用パスワード Verifying - Enter pass phrase for server.key: ←もう一度
| options | 意味 |
| genrsa | 作成する鍵を指定するオプション。今回は「RSA」というタイプの鍵を作成する。 |
| -des3 | どの鍵作成のアルゴリズムを使用するか指定するオプション。 今回は「DES3」というアルゴリズムを使用する。 |
| -out | 鍵ファイルの名前を指定するオプション。 「server.key」という名前で保存する。 |
| 1024 | 鍵の長さを指定する。今回は1024ビットにする。 |
※apacheのバージョンを上げる際は
次は(自己)証明書を作成する。 格納するディレクトリは /usr/local/apache2/conf/ssl.crt だ。
# mkdir /usr/local/apache2.0.51/conf/ssl.crt # cd /usr/local/apache2.0.51/conf/ssl.crt/ /usr/local/apache2.0.51/conf/ssl.crt # /usr/local/ssl/bin/openssl req -new -x509 -days 365 -key ../ssl.key/server.key -out server.crt (1行で) Enter pass phrase for ../ssl.key/server.key: ←ssl専用パスワード 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) [AU]:JP State or Province Name (full name) [Some-State]:Chiba Locality Name (eg, city) []:. Organization Name (eg, company) [Internet Widgits Pty Ltd]:. Organizational Unit Name (eg, section) []:. Common Name (eg, YOUR name) []:hjk.homedns.org Email Address []:webmaster@hjk.homedns.org
| options | 意味 |
| req | 証明書の署名要求(CSR)の作成をするオプション。 自己証明書を作成する為、指定する。 |
| -new | 新規に証明書要求ファイルを作成するオプション。 |
| -x509 | X.509形式の証明書要求ファイルを作成するオプション。 |
| -days | 証明書の有効期限を指定するオプション。今回は365日(1年)とする。 |
| -key | 入力する秘密鍵のファイル名を指定するオプション。 ここは上記で作成した、秘密鍵の鍵ファイル「server.key」を指定する。 |
| -out | 出力する証明書のファイル名を指定するオプション。 「server.crt」という名前で保存する。 |
※apacheのバージョンを上げる際は
ここで一度、/usr/local/apache2/bin/apachectrl startssl してみる。
# /usr/local/apache2/bin/apachectl startssl Password: ←これはsudo使ってたんでユーザパスワード。ルートならでない。 Apache/2.0.51 mod_ssl/2.0.51 (Pass Phrase Dialog) Some of your private key files are encrypted for security reasons. In order to read them you have to provide us with the pass phrases. Server hjk.homedns.org:443 (RSA) Enter pass phrase: ←ssl専用パスワード Ok: Pass Phrase Dialog successful.↑このように startssl を起動させると、逐一 ssl 起動のためのパスワードを 要求される。 (後ろでは暗号化された秘密鍵を使用してサーバ証明書を作成しているためんだそうな)
# cd /usr/local/apache2.0.51/conf/ssl.key/ /usr/local/apache2.0.51/conf/ssl.key # /usr/local/ssl/bin/openssl rsa -in server.key -out server.key (1行で) Enter pass phrase for server.key: writing RSA key
| options | 意味 |
| rsa | 作成する鍵の種類を指定する。今回はRSA鍵なんで、「rsa」と指定する。 |
| -in | 暗号化された鍵を指定するオプション。 暗号化して作成した「server.key」を指定する。 |
| -out | 出力する証明書のファイル名を指定するオプション。 暗号化していた「server.key」と同じ名前で保存する。 |
# /usr/local/apache2/bin/apachectl stop # /usr/local/apache2/bin/apachectl startssl # ps axfw | grep httpd ←httpdの起動確認 1259 pts/0 S 0:00 \_ grep httpd 1252 ? S 0:01 /usr/local/apache2.0.51/bin/httpd -k start -DSSL 1253 ? S 0:00 \_ /usr/local/apache2.0.51/bin/httpd -k start -DSSL 1254 ? S 0:00 \_ /usr/local/apache2.0.51/bin/httpd -k start -DSSL 1255 ? S 0:00 \_ /usr/local/apache2.0.51/bin/httpd -k start -DSSL 1256 ? S 0:00 \_ /usr/local/apache2.0.51/bin/httpd -k start -DSSL 1257 ? S 0:00 \_ /usr/local/apache2.0.51/bin/httpd -k start -DSSL 最後の"DSSL"がsslで起動している、という意味なんだそうな。 # netstat -pln ←使用しているポートの確認 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:32768 0.0.0.0:* LISTEN 200/rpc.statd tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN 205/inetd tcp 0 0 0.0.0.0:9 0.0.0.0:* LISTEN 205/inetd tcp 0 0 0.0.0.0:13 0.0.0.0:* LISTEN 205/inetd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 137/portmap tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1252/httpd tcp 0 0 0.0.0.0:113 0.0.0.0:* LISTEN 205/inetd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 214/sshd tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1252/httpd Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path ↑80/tcp及び443/tcpポートをhttpdが利用していることがわかるね。
< IfModule mod_ssl.c>
Include conf/ssl.conf
< /IfModule>
…あった。
ということで、ssl.confを編集する。
--- L.85-92 --- # General setup for the virtual host DocumentRoot "/export" ServerName hjk.homedns.org:443 ServerAdmin webmaster@hjk.homedns.org ErrorLog logs/error_log #TransferLog logs/access_log #ErrorLog /usr/local/apache2.0.51/logs/error_log #TransferLog /usr/local/apache2.0.51/logs/access_log --- L.110 --- #SSLCertificateFile /usr/local/apache2.0.51/conf/cert/hjk.crt SSLCertificateFile /usr/local/apache2.0.51/conf/ssl.crt/server.crt #SSLCertificateFile /usr/local/apache2.0.51/conf/ssl.crt/server-dsa.crt --- L.119 --- #SSLCertificateKeyFile /usr/local/apache2.0.51/conf/cert/hjk.pem SSLCertificateKeyFile /usr/local/apache2.0.51/conf/ssl.key/server.key #SSLCertificateKeyFile /usr/local/apache2.0.51/conf/ssl.key/server-dsa.key以後バージョンアップの際は、一度ローカルに ssl.conf を落としてきて、 emacs上で
# vi /export/home1/dav/index.html < html> < head> < title> ssl test page < /title> < /head> < body> SSL TOP PAGE! < /body> < /html>
次はアパッチを起動して接続確認!
# /usr/local/apach2/bin/apachectl startssl startではない点に注意
(WebDAV用の共有ディレクトリを作成) # mkdir /export/dav # chown apache.www /export/dav/ (WebDAV用のロックファイルを置くディレクトリを作成) # mkdir /export/var/DAVLock # chown apache.www /export/var/DAVLock (webDAVユーザ用ディレクトリの作成) # mkdir /export/dav/user01 # chown webmaster.export /export/dav/user01 ←ホームページ作成ユーザで管理できるように webmaster.exportでオーナー設定 # chown 747 /export/dav/user01 ←ディレクトリユーザのみ 読み・書き・実行 ができるように
# cd /export/ パスワードファイルを作りたい場所へ移動 /export# /usr/local/apache2.0.51/bin/htpasswd -c .privatekey hjk New password: Re-type new password: Adding password for user hjk
# cd /export/ パスワードファイルを作りたい場所へ移動 /export# /usr/local/apache2.0.52/bin/htdigest -c .htdigest picure hujioka Adding password for hujioka in realm picure. (1行で) New password: Re-type new password: (二人目からは "-c" を除いてユーザを追加していく) /export# /usr/local/apache2.0.52/bin/htdigest .htdigest picure kusaka Adding user kusaka in realm picure New password: Re-type new password:形式としては
【BASIC認証編】 Alias /hjk "/export/dav/private/hjk" < Location /hjk> Dav on SSLRequireSSL ←sslのみで通信 AllowOverride None Options None AuthUserFile /export/.privatekey AuthName hjk AuthType Basic Require user hjk < /Location> DavLockDB /export/var/DAVLock 【DIGEST認証編】 Alias /picure "/export/dav/picure" < Location /picure> Dav on AllowOverride None Options None AuthDigestFile /export/.htdigest AuthName picure user登録の中で指定した"realem"と同じ名称を指定する AuthType Digest < LimitExcept GET HEAD OPTIONS> Require user valid-user < /LimitExcept> < /Location> DavLockDB /export/var/DAVLock
【ステップ1 〜webDAVディレクトリ作成〜】 /export/dav# mkdir hoge /export/dav# chown webmaster.export hoge /export/dav# chmod 747 hoge/ 【ステップ2 〜ユーザ作成〜】 ~$ cd /export/ /export# /usr/local/apache2/bin/htpasswd .privatekey user02 New password: Re-type new password: Adding password for user user02 【ステップ3 〜グループファイル作成】 /export# touch .hogealia /export# vi .hogealia ------------ .hoge-user -------------- picure: hujioka user02 -------------------------------------- 【ステップ4 〜httpd.confへの登録〜】 Alias /hoge "/export/dav/hoge" ←変更1 < Location /hoge> ←変更2 Dav on SSLRequireSSL AllowOverride None Options None AuthUserFile /export/.privatekey ←パスワードは個人用で済ます AuthGroupFile /export/.hogealia ←グループファイル場所を指定 AuthName hoge ←変更5 AuthType Basic Require group hoge ←アクセスしたいグループ名 グループファイル名 < /Location>
準備として、
WebDAV Resources JPから
mod_encoding 20021209.tar.gz (2002/12/9) と
Apache 2.0 mod_encoding for Apache2 20040616版 (2004/06/16)
をとってくる(2004/09/22現在)。
これをサーバの適当な場所(この場合は"/usr/local/src")に置いておく。
/usr/local/src# tar zxvf mod_encoding-20021209.tar.gz /usr/local/src# cd mod_encoding-20021209 /usr/local/src/mod_encoding-20021209# ls AUTHORS Makefile.in acconfig.h install-sh stamp-h.in COPYING Makefile.simple aclocal.m4 lib ChangeLog NEWS config.h.in missing INSTALL README configure mkinstalldirs Makefile.am README.JP configure.in mod_encoding.c次にこの展開したファイルの中にある、mod_encoding.cを、 mod_encoding.c.apache2.20040616で置き換える。 mod_encoding.c.apache2.20040616がmod_encoding-20021209.tar.gz と同じディレクトリにあったとして、以下の用に置き換える。
/usr/local/src/mod_encoding-20021209 # cp ../mod_encoding.c.apache2.20040616 mod_encoding.c (1行で)下準備に"iconv_hook"ライブラリの作成をしてこれをインストールする。 できたライブラリは"/usr/local/lib"の下に置かれる。
/usr/local/src/mod_encoding-20021209# cd lib/ /usr/local/src/mod_encoding-20021209/lib# ls AUTHORS acconfig.h iconv_hook.c identify_encoding.c COPYING aclocal.m4 iconv_hook.h identify_encoding.h ChangeLog config.guess iconv_hook_default.c install-sh INSTALL config.h.in iconv_hook_eucjp.c ltmain.sh Makefile.am config.sub iconv_hook_ja_auto.c missing Makefile.in configure iconv_hook_mssjis.c mkinstalldirs NEWS configure.in iconv_hook_ucs2_cp932.c stamp-h.in README cp.h iconv_hook_utf8_cp932.c ucs2_cp932.h README.JP iconv.h.replace iconv_hook_utf8_eucjp.c /usr/local/src/mod_encoding-20021209/lib# ./configure /usr/local/src/mod_encoding-20021209/lib# make /usr/local/src/mod_encoding-20021209/lib# make install次に"mod_encoding"本体の作成をする。 Configureスクリプトの引数 "--with-apxs"の値は Apacheのインストールされている場所に合わせて適宜指定する。
/usr/local/src/mod_encoding-20021209/lib# cd .. /usr/local/src/mod_encoding-20021209 # ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-iconv-hook=/usr/local/include --prefix=/usr/local (1行で) /usr/local/src/mod_encoding-20021209# makeこの作業結果として、"mod_encoding.o"というオブジェクトファイルが生成される。 これをApacheのモジュールである、拡張子が".so"となるファイルに変換する。
/usr/local/src/mod_encoding-20021209# ls AUTHORS Makefile.simple config.h lib mod_encoding.slo COPYING NEWS config.h.in missing stamp-h ChangeLog README config.log mkinstalldirs stamp-h.in INSTALL README.JP config.status mod_encoding.c Makefile acconfig.h configure mod_encoding.la Makefile.am aclocal.m4 configure.in mod_encoding.lo Makefile.in config.cache install-sh mod_encoding.o [Makefile の編集 (必要ないかも)] (変更前) LIBS = -liconv_hook (変更後) LIBS = -I/usr/local/include -L/usr/local/lib -L./lib -liconv_hook /usr/local/src/mod_encoding-20021209 # gcc -shared -o mod_encoding.so mod_encoding.o -Wc,-Wall -L /usr/local/lib -Llib -liconv_hook (1行で) /usr/local/src/mod_encoding-20021209# ls AUTHORS Makefile.simple config.h lib mod_encoding.slo COPYING NEWS config.h.in missing mod_encoding.so ChangeLog README config.log mkinstalldirs stamp-h INSTALL README.JP config.status mod_encoding.c stamp-h.in Makefile acconfig.h configure mod_encoding.la Makefile.am aclocal.m4 configure.in mod_encoding.lo Makefile.in config.cache install-sh mod_encoding.oこの作業結果として、"mod_encoding.so"というファイルが生成された。 これを"/usr/local/apache2/modules"にコピーする。
/usr/local/src/mod_encoding-20021209 # cp mod_encoding.so /usr/local/apache2/modules/ (1行で)"httpd.conf"に次の設定を加える。
LoadModule encoding_module modules/encoding.soここで # /usr/local/apache2/bin/apachectrl configtest をかけてみると 次のようなエラーがでるかもしれない。EncodingEngine on NormalizeUsername on SetServerEncoding UTF-8 DefalultClientEncoding JA-AUTO-SJIS-MS SJIS AddClientEncoding "cadaver/" EUC-JP
LoadModule encoding_module modules/mod_encoding.so LoadFile /usr/local/lib/libiconv_hook.so ←追記