mac Apache2.2のSSL環境構築(メモ)
前提
$ port installed | grep apache2 apache2 @2.2.14_0+darwin+preforkmpm (active) ... $ port installed | grep openssl openssl @0.9.8k_0+darwin (active) ...
プライベートCA(認証局)の作成
$ cd /opt/local/etc/openssl/ $ sudo ./misc/CA.sh -newca CA certificate filename (or enter to create) Making CA certificate ... Generating a 1024 bit RSA private key .............................++++++ .............................................++++++ writing new private key to './demoCA/private/./cakey.pem' Enter PEM pass phrase: <-----CA用パスフレーズ Verifying - Enter PEM pass phrase:<-----再入力 ----- 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]: 【ENTER】 State or Province Name (full name) [Some-State]:【ENTER】 Locality Name (eg, city) []:【ENTER】 Organization Name (eg, company) [Internet Widgits Pty Ltd]:【ENTER】 Organizational Unit Name (eg, section) []:【ENTER】 Common Name (eg, YOUR name) []:private<----ここだけ【private】にした Email Address []:【ENTER】 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:【ENTER】 An optional company name []:【ENTER】 Using configuration from /opt/local/etc/openssl/openssl.cnf Enter pass phrase for ./demoCA/private/./cakey.pem:<------先ほどのパスフレーズを入れる Check that the request matches the signature Signature ok Certificate Details: .........(中略)........... Write out database with 1 new entries Data Base Updated
サーバー秘密鍵の作成
$ cd /opt/local/apache2/conf $ sudo mkdir openssl $ cd openssl $ sudo openssl genrsa -out apache2.key -des3 1024 $ sudo openssl rsa -in apache2.key -out apache2_nopasswd.key $ sudo openssl req -new -key apache2_nopasswd.key -out apache2.csr ....(いろいろ訊かれるが全部エンター。Common Nameだけ前述の【private】にする)
サーバー証明書の作成
$ cd /opt/local/etc/openssl (なぜかわからないけど、demoCA/index.txtを空にしておかないとうまく行かなかったので) $ sudo rm demoCA/index.txt $ sudo touch demoCA/index.txt $ sudo openssl ca -in /opt/local/apache2/conf/openssl/apache2.csr -out /opt/local/apache2/conf/openssl/apache2.crt
これで秘密鍵と証明書ができた
$ ls -l /opt/local/apache2/conf/openssl -rw-r--r-- 1 root admin 3071 11 16 16:28 apache2.crt -rw-r--r-- 1 root admin 631 11 16 16:28 apache2.csr -rw-r--r-- 1 root admin 963 11 16 16:23 apache2.key -rw-r--r-- 1 root admin 891 11 16 16:23 apache2_nopasswd.key
httpd-ssl.confの編集
(ファイルの中身) Listen 443 <VirtualHost *:443> DocumentRoot "/opt/local/apache2/htdocs" SSLEngine on SSLCertificateFile "/opt/local/apache2/conf/openssl/apache2.crt" SSLCertificateKeyFile "/opt/local/apache2/conf/openssl/apache2_nopasswd.key" </VirtualHost>
動作確認
ブラウザからhttps://localhostにアクセスして、ブラウジングできればOK
開発環境構築は、パッケージ管理システムを使おう
本番環境ではないわけだし、サーバーの性能最適化・細部の設定が求められている訳でもなく、セキュリティを考慮する必要もない(前提に置く必要はある)。わざわざソースを入手してオプションを設定してコンパイルしたり、依存関係で悩んだりするよりかは、ある程度aptとかportとかに任せちゃった方がいい。って思った。
PHP 5.3.0のビルド&インストール
ソースの入手
$ cd ~/src # wget http://jp2.php.net/distributions/php-5.3.0.tar.gz # tar zxvf php-5.3.0.tar.gz # cd php-5.3.0
configure optionの整理
config.yyyymmddファイルを作成しそこでオプションを指定
(config.yyyymmddファイルの中身) ./configure \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-libxml-dir= --with-openssl
Apacheのビルド・インストール・設定
$ mkdir src $ cd src $ wget http://ftp.riken.jp/net/apache/httpd/httpd-2.0.63.tar.gz $ tar zxvf httpd-2.0.63.tar.gz $ cd httpd-2.0.63 $ ./configure --enable-mods-shared=all
ちなみに、--enable-mods-sharedオプションだと、rewrite, dav、vhost_aliasなどが入るけど、sslとかproxyとかsuexecとかは入らないみたい。
ビルドして、インストール。--prefixを指定してないので/usr/local/apache2にインストールされる
$ make $ sudo make install
$ emacs ~/.bashrc (ファイルの最後に以下を追加) export PATH=/usr/local/apache2/bin:$PATH $ source ~/.bashrc (動作確認) $ httpd -v Server version: Apache/2.0.63 Server built: Oct 5 2009 11:11:28 $ httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c $ sudo /usr/local/apache2/bin/apachectl start httpd: Could not determine the server\'s fully qualified domain name, using 192.168.11.5 for ServerName $ ps auxc | grep apache2 root 26909 0.0 0.4 4748 2156 ? Ss 11:20 0:00 httpd nobody 26910 0.0 0.4 4748 2164 ? S 11:20 0:00 httpd nobody 26911 0.0 0.2 4748 1544 ? S 11:20 0:00 httpd nobody 26912 0.0 0.2 4748 1544 ? S 11:20 0:00 httpd nobody 26913 0.0 0.2 4748 1544 ? S 11:20 0:00 httpd nobody 26914 0.0 0.2 4748 1544 ? S 11:20 0:00 httpd nobody 26915 0.0 0.2 4748 1544 ? S 11:21 0:00 httpd (起動してますね) $ sudo /usr/local/apache2/bin/apachectl stop
次にapache実行ユーザーの作成
$ sudo addgroup --system apache Adding group `apache' (GID 107) ... 終了。 $ sudo adduser --system --no-create-home --ingroup apache apache Adding system user `apache' (UID 105) ... Adding new user `apache' (UID 105) with group `apache' ... Not creating home directory `/home/apache'.
続いてhttpd.confの編集
VirtualHostの設定で、~/www以下で開発できるようにしておく
.... User apache Group apache .... NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /home/showtarow/www </VirtualHost>
Windows XPにDebianをインストール
まずcoLinux本体とディスクイメージを入手&インストール
インストールするDebianはDebian Lenny 5.0.2
入手元は・・・
(本体)
http://downloads.sourceforge.net/project/colinux/Images%202.6.x%20Debian/Debian%205.0%20Lenny/Debian-5.0r2-lenny.7z?use_mirror=jaist
普通にインストール(なおインストール先はC:\coLinuxにした)する。
TAP-Win32 Apapterもいれる。
confファイルの設定
ダウンロードしたDebian-5.0r2-lenny.7zを解凍して、
- Debian-5.0r2-lenny.ext3.2gbをroot_fsにリネームしてC:\coLinuxに移動
- debian-lenny.confをdebian.confにリネームしてC:\coLinuxに移動
debian.confの中身は以下の通り
kernel=vmlinux cobd0="c:\coLinux\root_fs" cobd1="c:\coLinux\swap.img" root=/dev/cobd0 #ro initrd=initrd.gz mem=512 #cocon=120x40 eth0=tuntap #ttys0=COM1,"BAUD=115200 PARITY=n DATA=8 STOP=1 dtr=on rts=on" #exec0=C:\Programs\Xming\Xming.exe,":0 -clipboard -multiwindow -ac"
swapイメージの作成
windowsのコマンドプロンプトを立ち上げて、512MBのswapイメージを作成する
C:\coLinux>fsutil file createnew swap.img 536870912
ネットワークの設定
既存のローカルエリア接続と新たに作成されたTAP-Win32のローカルエリア接続の両方を選択して、右クリック、「ブリッジ接続する」をクリック。
以下まだメモ
kernel=vmlinux cobd0="root_fs" cobd1="swap.disk" root=/dev/cobd0 #ro initrd=initrd.gz mem=512 #cocon=120x40 #eth0=slirp eth1=tuntap #ttys0=COM1,"BAUD=115200 PARITY=n DATA=8 STOP=1 dtr=on rts=on" #exec0=C:\Programs\Xming\Xming.exe,":0 -clipboard -multiwindow -ac"
Apacheを入れる
# cd ~ # mkdir src # cd src # wget http://ftp.riken.jp/net/apache/httpd/httpd-2.0.63.tar.gz # tar zxvf httpd-2.0.63.tar.gz # cd httpd-2.0.63 # ./configure --enable-mods-shared=all # make # sudo make install (インストール完了の確認) # /usr/local/apache2/bin/httpd -v Server version: Apache/2.0.63 Server built: Oct 5 2009 11:11:28 (コンパイル済みモジュールの確認) # /usr/local/apache2/bin/httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c <----- enable-mods-shared=all にしたのでこうなる (Apacheの実行ユーザーの作成) # sudo addgroup --system apache # sudo adduser --system --no-create-home --ingroup apache apache (開発用ディレクトリの作成) # mkdir ~/www # echo "hogehoge" > ~/www/index.html <----動作確認用 (confファイルの編集) # sudo emacs /usr/local/apache2/conf/httpd.conf 〜〜〜〜〜〜(中略)〜〜〜〜〜〜 (実行ユーザーの指定) User apache Group apache 〜〜〜〜〜〜(中略)〜〜〜〜〜〜 (開発用ディレクトリをVirtualHostで指定) NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /home/showtarow/www </VirtualHost> 〜〜〜〜〜〜(中略)〜〜〜〜〜〜 # /usr/local/apache/bin/apachectl start ブラウザからアクセスすると先ほどの"hogehoge"が表示される