#freeze
''目次''
#contents
~
----
*準備 [#bf506fb8]
-JAPAN APACHE USERS GROUP -- http://www.apache.jp/~
ソース:httpd-2.2.21.tar.gz
*インストール [#ifd4713f]
+ソースの取得~
/usr/local/srcにhttpd-2.2.21.tar.gzを取得。
# wget -P /usr/local/src http://www.ring.gr.jp/archives/net/apache/httpd/httpd-2.2.21.tar.gz
+ソースの解凍~
/usr/local/srcにhttpd-2.2.21フォルダが作成される。
# cd /usr/local/src
# tar zxvf httpd-2.2.21.tar.gz
+APR(Apache Portable Runtime)のインストール~
++apr(1.4.5)~
[[configureのヘルプ>apr-1.4.5のconfigureヘルプ]]
# cd /usr/local/src/httpd-2.2.21/srclib/apr
# ./configure --prefix=/usr/local/httpd-2.2.21/apr
# make
# make install
++apr-util(1.3.12)~
[[configureのヘルプ>apr-util-1.3.12のconfigureヘルプ]]
# cd /usr/local/src/httpd-2.2.21/srclib/apr-util
# ./configure --prefix=/usr/local/httpd-2.2.21/apr-util --with-apr=/usr/local/httpd-2.2.21/apr
# make
# make install
+コンパイル設定~
[[configureのヘルプ>httpd-2.2.21のconfigureヘルプ]]
# cd /usr/local/src/httpd-2.2.21
# ./configure \
> --prefix=/usr/local/httpd-2.2.21 \
> --enable-so \
> --enable-rewrite=shared \
> --enable-dav=shared \
> --enable-dav-fs=shared \
> --enable-dav-lock=shared \
> --enable-ssl=shared \
> --with-ssl=/usr/local/ssl/ \
> --with-apr=/usr/local/httpd-2.2.21/apr \
> --with-apr-util=/usr/local/httpd-2.2.21/apr-util
+インストール~
# make
# make install
+シンボリックリンクの作成~
# ln -s /usr/local/httpd-2.2.21 /usr/local/apache2
*初期設定 [#padbc3f5]
-''apacheユーザーの作成''~
apache専用のユーザーを作成する。ユーザー名はapache。
# groupadd apache
# useradd -g apache apache
-''httpd.confの設定''
# vi /usr/local/apache2/conf/httpd.conf
ユーザーとグループの変更
User daemon
Group daemon
↓
User apache
Group apache
サーバー名の設定
ServerName www.example.com:80
↓
ServerName XXXXXXXXXXX:80
*SSL対応設定 [#jd5686d3]
**認証局(CA)の構築 [#o83fff79]
-秘密鍵と証明書の作成~
CA.shという用意されたスクリプトを使用
# cd /usr/local/ssl
# cp misc/CA.sh .
# ./CA.sh -newca
CA certificate filename (or enter to create) ← 空Enter
Making CA certificate ...
Generating a 1024 bit RSA private key
.....++++++
................++++++
writing new private key to './demoCA/private/./cakey.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]: ← 県名
Locality Name (eg, city) []: ← 市町村
Organization Name (eg, company) [Internet Widgits Pty 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 []: ← 空Enter
An optional company name []: ← 空Enter
Enter pass phrase for ./demoCA/private/./cakey.pem: ← 秘密鍵のパスフレーズを入力
(※)サーバのURL(またはサーバ名?)にしないとApacheLogに警告が出力されてた。
以上の処理により、~
~
/usr/local/ssl/demoCA/cacert.pem ← 自己署名型CA証明書~
/usr/local/ssl/demoCA/private/cakey.pem ← 秘密鍵~
~
が作成される。~
秘密鍵は他人に見られないように
# chmod 600 /usr/local/ssl/demoCA/private/cakey.pem
# chmod 700 /usr/local/ssl/demoCA/private
とパーミッションを設定しておく。~
証明書を確認するには以下のようにする。
# openssl x509 -in /usr/local/ssl/demoCA/cacert.pem -text
**SSLサーバ構築 [#v775bffe]
-サーバ秘密鍵の作成
# openssl genrsa -out server.key 1024
Generating RSA private key, 1024 bit long modules
.............++++++
....++++++
e is 65537 (0x10001)
確認
# ls
server.key
-証明書署名要求(CSR)の作成
# openssl req -new -key server.key -out server.csr
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]: ← 県名
Locality Name (eg, city) []: ← 市町村
Organization Name (eg, company) [Internet Widgits Pty 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 []: ← 空Enter
An optional company name []: ← 空Enter
(※)サーバのURL(またはサーバ名?)にしないとApacheLogに警告が出力されてた。
確認
# ls
server.key server.csr
-証明書への自己署名
# echo 01 > ca-cert.srl
# openssl x509 -CA demoCA/cacert.pem -CAkey demoCA/private/cakey.pem -CAserial ca-cert.srl -req -days 3650 -in server.csr -out server.crt
Using configuration from /usr/local/ssl/openssl.cnf
Enter pass phrase for /usr/local/ssl/demoCA/private/cakey.pem: ← 秘密鍵のパスフレーズを入力
(中略)
Sign the certificate? [y/n]: y ← [y]+Enter
1 out of 1 certificate requests sertified, commit? [y/n]: ← [y]+Enter
確認
# ls
server.key server.csr server.crt
秘密鍵と証明書を移動する。
# mkdir /usr/local/apache2/conf/ssl
# mv server.key /usr/local/apache2/conf/ssl
# mv server.crt /usr/local/apache2/conf/ssl
**Apacheへの埋め込み [#va60a738]
-''httpd-ssl.confの設定''
# vi /usr/local/apache2/conf/extra/httpd-ssl.conf
サーバー名
<VirtualHost _default_:443>
ServerName www.example.com:443
↓
ServerName XXXXXXXXXXXXXXX:443
サーバー証明書のパス
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
↓
SSLCertificateFile "/usr/local/apache2/conf/ssl/server.crt"
秘密鍵のパス
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
↓
SSLCertificateKeyFile "/usr/local/apache2/conf/ssl/server.key"
-''httpd.confの設定''
SSL用設定ファイルの有効化
# vi /usr/local/apache2/conf/httpd.conf
SSL設定ファイルのリンク
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
↓
Include conf/extra/httpd-ssl.conf ← コメント外す
確認
# /usr/local/apache2/bin/apachectl configtest
Syntax OK
*起動 [#hc2eda9e]
下記のコマンドで起動、停止、再起動を行う
# /usr/local/apache2/bin/apachectl start ← 起動
# /usr/local/apache2/bin/apachectl stop ← 停止
# /usr/local/apache2/bin/apachectl restart ← 再起動
*動作確認 [#ybd5d995]
http,httpsでそれぞれアクセスし「It works!」が表示されればOK。~
*自動起動設定 [#i5e47ca8]
-''起動スクリプトのコピー''
# cp /usr/local/src/httpd-2.2.21/build/rpm/httpd.init /etc/rc.d/init.d/httpd
-''起動スクリプトの編集''~
[[デフォルト起動スクリプト>デフォルト起動スクリプト Apache 2.2.21]]
# vi /etc/rc.d/init.d/httpd
httpd=${HTTPD-/usr/sbin/httpd}
↓
httpd=${HTTPD-/usr/local/apache2/bin/httpd} ← パスの変更
(〜check13()の中〜)
CONFFILE=/etc/httpd/conf/httpd.conf
↓
CONFFILE=/usr/local/apache2/conf/httpd.conf ← パスの変更
-''実行権限を与えて自動起動設定''
# chmod 755 /etc/rc.d/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
*他 [#g59cce4a]
**''STOPに失敗する'' [#m00d1437]
上記の手順でインストールするとhttpdスクリプトでstopさせる時に失敗してしまう。
# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]
# /etc/rc.d/init.d/httpd stop
httpd を停止中: [失敗]
~
pidファイルの位置が違っているのが原因みたい。~
# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]
# find / -name *.pid
/var/run/abrtd.pid
/var/run/syslogd.pid
/var/run/sshd.pid
/var/run/crond.pid
/var/run/messagebus.pid
/var/run/haldaemon.pid
/usr/local/httpd-2.2.21/logs/httpd.pid ← ここにpidファイルが作成されている
httpd起動スクリプトでは
pidfile=${PIDFILE-/var/log/httpd/${prog}.pid}
と記述されている。~
''[[Apache HTTP サーバ バージョン 2.2 ドキュメント>http://httpd.apache.org/docs/2.2/]]''によるとpid作成先を設定するディレクティブは''PidFile''でデフォルトは''logs/httpd.pid''になるみたい。~
httpd.confには記述が無いので追加する。~
# vi /usr/local/apache2/conf/httpd.conf
PidFile /var/run/httpd.pid ← ServerRootの次ぐらいの行に追加
httpd起動スクリプトも修正する。
# vi /etc/rc.d/init.d/httpd
#pidfile=${PIDFILE-/var/log/httpd/${prog}.pid} ← コメントアウト
pidfile=${PIDFILE-/var/run/httpd.pid} ← 追加
テスト
# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]
# find / -name *.pid
/var/run/abrtd.pid
/var/run/syslogd.pid
/var/run/sshd.pid
/var/run/crond.pid
/var/run/httpd.pid ←
/var/run/messagebus.pid
/var/run/haldaemon.pid
# /etc/rc.d/init.d/httpd stop
httpd を停止中: [ OK ]
~
**''STOPに失敗する その2'' [#a50e6c04]
conf/extra/httpd-mpm.confにPidFileディレクティブの記述があるがソースからコンパイルするとhttpd.confでextra/httpd-mpm.confがincludeされない(?)ようである。~
httpd-mpm.confでPidFileのパスを修正し、httpd.confでextra/httpd-mpm.confをincludeさせてもOKかと。
# vi /usr/local/apache2/conf/extra/httpd-mpm.conf
#PidFile "logs/httpd.pid"
↓
PidFile "/var/run/httpd.pid"
#LockFile "logs/httpd/accept.lock"
↓
LockFile "/var/lock/subsys/httpd"
# vi /usr/local/apache2/conf/httpd.conf
# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf
↓
Include conf/extra/httpd-mpm.conf ← コメント外す
httpd起動スクリプトの修正は同じ。