Apache + SSL のインストール
1999-08-29 作成 福島
2001-01-10 更新 福島
1) OpenSSL をインストール。
$ tar zxf openssl-0.9.4.tar.gz $ cd openssl-0.9.4 $ ./config $ make $ make rehash $ make test $ su # make install
2) Apache のソースと SSL セットを展開。
$ tar zxf apache_1.3.6.tar.gz $ cd apache_1.3.6 $ tar zxf apache_1_3_6+ssl_1_36_tar.gz
3) Apache に SSL パッチを当てる。
$ patch -p1 < SSLpatch
4) Apache の src/Configuration を OpenSSL に合わせて変更。(src/Configuration.tmpl も同様に変更)
# # SSL Related stuff. N.B. This is set up to use the SSLeay source, NOT an # installed version. # #KEYNOTE_BASE=/home/ben/work/KeyNote SSL_BASE=/usr/local/ssl SSL_INCLUDE= -I$(SSL_BASE)/include SSL_CFLAGS= -DAPACHE_SSL SSL_LIB_DIR= $(SSL_BASE)/lib SSL_LIBS= -L$(SSL_LIB_DIR) -lssl -lcrypto SSL_APP_DIR= $(SSL_BASE)/bin #SSL_APP=/usr/home/ben/work/openssl/apps/openssl
5) Apache をコンパイル。
$ ./configure $ cd src $ ./Configure $ cd .. $ make $ su # make install
6) gcache をインストール。
# cp src/modules/ssl/gcache /usr/local/apache/bin/
7) 鍵とサイト証明書を格納するディレクトリを作成。
$ su # mkdir /usr/local/apache/ssl # cd /usr/local/apache/ssl
8) 鍵とサイト証明書のリクエストを作成。
# /usr/local/ssl/bin/openssl req -new > new.cert.csr Using configuration from /usr/local/ssl/lib/openssl.cnf Generating a 1024 bit RSA private key ........+++++ .......................+++++ writing new private key to 'httpsd.pem' writing new private key to 'privkey.pem' Enter PEM pass phrase:********(鍵に設定するパスワードを入力) Verifying password - 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]:JP State or Province Name (full name) [Some-State]:Saitama Locality Name (eg, city) []:Omiya Organization Name (eg, company) [Internet Widgits Pty Ltd]:Rouge Network Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:monolith.example.com(サーバの FQDN を記述する) Email Address []:admin@monolith.example.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
9) Apache-SSL の起動時にパスワードを聞かれるのを抑止するため、鍵からパスワードを削除。
# /usr/local/ssl/bin/openssl rsa -in privkey.pem -out new.cert.key read RSA private key Enter PEM pass phrase:********(先刻入力したパスワードを入力) writing RSA private key
10) リクエストを署名された証明書に変換。
(本来はベリサイン等の認証局で発行してもらう) # /usr/local/ssl/bin/openssl x509 -in new.cert.csr -out new.cert.cert -req -signkey new.cert.key
11) セキュア用ディレクトリを作成。
$ su # mkdir /usr/local/apache/htsdocs(https:// ドキュメント用ディレクトリ) # mkdir /usr/local/apache/cgi-bins(https:// CGI用ディレクトリ)
12) Apache の設定。(Apache 1.3.6 附属の httpd.conf-dist を /usr/local/apache/conf/httpd.conf として使用。)
Port 443 Listen 443 Listen 80 ServerType standalone ServerRoot "/usr/local/apache" ServerName monolith.example.com(CNAME しているので www サーバ名にする。) User nobody Group nogroup ServerAdmin admin@monolith.example.com(Web-Master のメールアドレス) #DocumentRoot "/usr/local/apache/htdocs"(デフォルトのドキュメントディレクトリを無効にする) #<Directory />(~user/* と .htaccess を有効にするためコメントアウト) # Options FollowSymLinks # AllowOverride None #</Directory> <Directory "/usr/local/apache/htdocs"> Alias /icons/ "/usr/local/apache/icons/" <Directory "/usr/local/apache/icons/"> ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"(http:// で参照されるCGIディレクトリ) <Directory "/usr/local/apache/cgi-bin"> UserDir(<VirtualHost>指定で許可/禁止するためにここで不使用にしておく。) HostnameLookups On SSLCacheServerPort logs/gcache_port SSLCacheServerPath bin/gcache SSLSessionCacheTimeout 300 SSLCertificateFile /usr/local/apache/ssl/new.cert.cert SSLCertificateKeyFile /usr/local/apache/ssl/new.cert.key SSLVerifyClient 0 SSLVerifyDepth 10 SSLFakeBasicAuth <VirtualHost _default_:80>(http:// 用設定) Port 80 SSLDisable DocumentRoot /usr/local/apache/htdocs(http://で参照されるディレクトリ) UserDir public_html(~user/ を許可する) AddHandler cgi-script .cgi(~user/xxx.cgi を許可する) <Directory /*/public_html>(~user/ に対する条件) <Limit GET POST OPTIONS PROPFIND> Order allow,deny Allow from all </Limit> </Directory> ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"(http:// 用 CGI ディレクトリ) <Directory "/usr/local/apache/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost _default_:443>(https:// 用設定) Port 443 SSLCertificateFile /usr/local/apache/ssl/new.cert.cert SSLCertificateKeyFile /usr/local/apache/ssl/new.cert.key SSLVerifyClient 0 SSLVerifyDepth 10 SSLFakeBasicAuth DocumentRoot /usr/local/apache/htsdocs(https://で参照されるディレクトリ) UserDir(~user/ を禁止) <Directory /*/public_html>(~user/ を禁止) <Limit GET POST OPTIONS PROPFIND> Order deny,allow Deny from all </Limit> </Directory> ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bins/"(https:// 用 CGI ディレクトリ) <Directory "/usr/local/apache/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> </VirtualHost>
13) Apache を起動。
# /usr/local/apache/bin/httpsd -f /usr/local/apache/conf/httpd.conf (-f で httpd.conf を指定しなくてもデフォルトで上記になる模様。)
14) init に登録。
SlackWare の場合 [/etc/rc.M] #Start Web server: if [ -x /etc/rc.d/rc.httpd ]; then . /etc/rc.d/rc.httpd fi [/etc/rc.d/rc.httpd](0755 root:root) /usr/local/apache/bin/httpsd RedHat の場合 [/etc/rc.d/apache](0755 root:root) #!/bin/sh . /etc/rc.d/init.d/functions [ -f /usr/local/apache/bin/httpsd ] || exit 0 case "$1" in start) echo -n "Starting Apache-SSL server: " /usr/local/apache/bin/httpsd echo ;; stop) echo -n "Stopping Apache-SSL server: " killproc httpsd echo ;; status) status httpsd ;; *) echo "Usage: $0 {start|stop|status}" exit 1 esac # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc0.d/K110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc1.d/K110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc2.d/S110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc4.d/S110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc5.d/S110apache # ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc6.d/K110apache
15) php のインストール。
$ tar zxf php-3.0.13.tar.gz $ cd php-3.0.13 $ ./configure --with-apache=../apache_1.3.6 --enable-track-vars $ make $ make install $ su # cp php3.ini-dist /usr/local/lib/php3.ini # exit
16) apache を再構築。(ついでに mod_auth_dbm, mod_auth_db も指定)
$ cd ../apache_1.3.6 $ ./configure --activate-module=src/modules/php3/libphp3.a --enable-module=auth_dbm --enable-module=auth_db php のマニュアルにもありますが、この libphp3.a は apache の make 時に出来上がるファイルです。 最初はありません。 また、AuthDBMUserFile ディレクティブがうまく動作しません。 代わりに AuthDBUserFile ディレクティブで動作します。 Apache 付属の dbmmanage を使用してパスワードDBを作成しているのに・・・。 $ make $ su # make install httpsd.conf に以下を追加(修正) Addtype application/x-httpd-php3 .php3 .phtml $ su # httpsdctl start