- 追加された行はこの色です。
- 削除された行はこの色です。
Apache2は[[こちら:http://www.stackasterisk.jp/tech/systemConstruction/apache09_03.jsp]]~
Apache-SSL+OpenSSL でも構築できるがモジュールとして使える mod_ssl+OpenSSL で構築することにする
#contents
*必要なパッケージの入手 [#vc9270ef]
apache_1.3.33.tar.gz -> http://www.apache.org/~
mod_ssl-2.8.22-1.3.33.tar.gz -> http://www.modssl.org/
*OpenSSLのインストール [#n46c7a4f]
opensslとopenssl-develはrpmパッケージでインストールされているものとする
*mod_sslのコンパイルとApacheのインストール [#y97d290d]
RedHat9でKerberosのヘッダが /usr/kerberos/include にあるためmakeエラーが発生します~
export CPPFLAGS=-I/usr/kerberos/include や export CPPFLAGS="-DOPENSSL_NO_KRB5" を試したけどうまくいかないので、以下のようにヘッダファイルをコピーしました
# cp /usr/kerberos/include/*.h /usr/include
# tar xvzf apache_1.3.33.tar.gz
# tar xvzf mod_ssl-2.8.22-1.3.33.tar.gz
# cd mod_ssl-2.8.22-1.3.33
# OPTIM="-O2" ./configure --with-apache=../apache_1.3.33 --with-ssl=SYSTEM --enable-rule=SHARED_CORE \
--with-layout=Apache --enable-module=so --enable-module=rewrite
# cd ../apache_1.3.33
# make
# make certificate
Signature Algorithm ((R)SA or (D)SA) [R]:R
1. Country Name (2 letter code) [XY]:JP ... 国コード(日本なのでJP)
2. State or Province Name (full name) [Snake Desert]:Shiga ... 州もしくは都道府県
3. Locality Name (eg, city) [Snake Town]:Otsu ... 市区郡町村
4. Organization Name (eg, company) [Snake Oil, Ltd]:Self ... 組織名や会社名
5. Organizational Unit Name (eg, section) [Webserver Team]:Engineer ... 組織内名称
6. Common Name (eg, FQDN) [www.snakeoil.dom]:www.example.com ... サーバー名
7. Email Address (eg, name@FQDN) [www@snakeoil.dom]:root@example.com ... 管理者メールアドレス
8. Certificate Validity (days) [365]:365
Certificate Version (1 or 3) [3]:3
Encrypt the private key 2005-11-21 (月) 19:39:18 [Y/n]: y
Enter PEM pass phrase: ... パスフレーズ
Verifying password - Enter PEM pass phrase: ... 再入力
RESULT: Server Certification Files
o conf/ssl.key/server.key
The PEM-encoded RSA private key file which you configure
with the 'SSLCertificateKeyFile' directive (automatically done
when you install via APACI). KEEP THIS FILE PRIVATE!
o conf/ssl.crt/server.crt
The PEM-encoded X.509 certificate file which you configure
with the 'SSLCertificateFile' directive (automatically done
when you install via APACI).
o conf/ssl.csr/server.csr
The PEM-encoded X.509 certificate signing request file which
you can send to an official Certificate Authority (CA) in order
to request a real server certificate (signed by this CA instead
of our demonstration-only Snake Oil CA) which later can replace
the conf/ssl.crt/server.crt file.
WARNING: Do not use this for real-life/production systems
# make install
*セキュア・サーバID申請準備 [#a814a7ac]
$ su
; 乱数ファイルの作成
# openssl md5 * > rand.dat
; 秘密鍵の作成
# openssl genrsa -rand rand.dat -des3 1024 > key.pem
; パスフレーズを2回入力
# rm -f rand.dat
; CSR作成(ベリサイン入力用)
# openssl req -new -key key.pem -out csr.pem
; さきほどのパスフレーズを入力
Country Name : JP
State or Province Name : Shiga
Locality Name : Otsu
Organization Unit Name : system-1
Common Name : www.example.com
Email Address
A challenge password
An optional company name
; key.pem, csr.pemは外部メディアに保管します
; csr.pemの内容よりベリサインからcert.pemを取得します
# rm -f csr.pem
# chmod 400 /usr/local/apache/conf/ssl.crt/cert.pem
# chmod 400 key.pem
# mv key.pem /usr/local/apache/conf/ssl.key
*httpd.confの設定 [#ob915c0d]
# vi httpd.conf
<IfDefine SSL>
Listen 80 # HTTP用
Listen 443 # SSL用
</IfDefine>
## ----- ここからの設定意味理解してません
## ----- とりあえずdefaultに書いてあったのでそのままコピー
##
## SSL Global Context
##
## All SSL configuration in this context applies both to
## the main server and all SSL-enabled virtual hosts.
##
#
# Some MIME-types for downloading Certificates and CRLs
#
<IfDefine SSL>
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
</IfDefine>
<IfModule mod_ssl.c>
# Pass Phrase Dialog:
# Configure the pass phrase gathering process.
# The filtering dialog program (`builtin' is a internal
# terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog builtin
# Inter-Process Session Cache:
# Configure the SSL Session Cache: First the mechanism
# to use and second the expiring timeout (in seconds).
#SSLSessionCache none
#SSLSessionCache shmht:/usr/local/apache/logs/ssl_scache(512000)
#SSLSessionCache shmcb:/usr/local/apache/logs/ssl_scache(512000)
SSLSessionCache dbm:/usr/local/apache/logs/ssl_scache
SSLSessionCacheTimeout 300
# Semaphore:
# Configure the path to the mutual exclusion semaphore the
# SSL engine uses internally for inter-process synchronization.
SSLMutex file:/usr/local/apache/logs/ssl_mutex
# Pseudo Random Number Generator (PRNG):
# Configure one or more sources to seed the PRNG of the
# SSL library. The seed data should be of good random quality.
# WARNING! On some platforms /dev/random blocks if not enough entropy
# is available. This means you then cannot use the /dev/random device
# because it would lead to very long connection times (as long as
# it requires to make more entropy available). But usually those
# platforms additionally provide a /dev/urandom device which doesn't
# block. So, if available, use this one instead. Read the mod_ssl User
# Manual for more details.
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random 512
#SSLRandomSeed startup file:/dev/urandom 512
#SSLRandomSeed connect file:/dev/random 512
#SSLRandomSeed connect file:/dev/urandom 512
# Logging:
# The home of the dedicated SSL protocol logfile. Errors are
# additionally duplicated in the general error log file. Put
# this somewhere where it cannot be used for symlink attacks on
# a real server (i.e. somewhere where only root can write).
# Log levels are (ascending order: higher ones include lower ones):
# none, error, warn, info, trace, debug.
SSLLog /usr/local/apache/logs/ssl_engine_log
SSLLogLevel info
</IfModule>
## ----- ここからバーチャルドメイン設定
NameVirtualHost *:80
# HTTP用
<VirtualHost *:80>
ServerAdmin root@example.com
DocumentRoot /home/user/public_html
ServerName www.example.com
ErrorLog /usr/local/apache/logs/error_log
CustomLog /usr/local/apache/logs/access_log combined
</VirtualHost>
# SSL用
<IfDefine SSL>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl.crt/cert.pem
SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/key.pem
ServerAdmin root@example.com
DocumentRoot /home/user/ssl_public_html
ServerName www.example.com
ErrorLog /usr/local/apache/logs/error_log
CustomLog /usr/local/apache/logs/ssl_access_log combined
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog /usr/local/apache/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfDefine>
*再起動前の準備 [#da987caf]
毎回起動時にパスフレーズを聞かれるのはめんどいし、自動起動も面倒なのでパスフレーズを削除する
# openssl rsa -in /usr/local/apache/conf/ssl.key/server.key -out /usr/local/apache/conf/ssl.key/server.key
&color(red){PHPを利用している場合はPHPもインストールしなおす必要があります};~
apache起動時に -DEAPI うんちゃらで怒られます
あとは以下を変更
-ログローテーションの追加~
-rc.local に記述している起動コマンドを startssl へ~
-mrtgでhttpdプロセス数を監視している場合は snmpd.conf ファイルを編集する必要があるかも
バーチャルホストの設定を確認するには
$ /usr/local/apache/bin/httpd -S
*Apacheの起動 [#w8fc4c9f]
# /usr/local/apache/bin/apachectl startssl
でスタート~
普通にstartすればSSLはサポートされず~
とめるときは stop で同じ
https:// でアクセスし画面が表示されればOK
*ネームベースからIPベースのバーチャルホストに移行する [#gbc82ed9]
SSLはプロトコルの特徴によりネームベースのバーチャルホストでは利用できない~
ネームベースはHTTPリクエストヘッダに含まれるHostを参照して判別するが、それ以前に証明書を交わす必要があるためです~
http://httpd.apache.org/docs/vhosts/name-based.html#namevip
すでにIP192.168.0.1でネームベースで運営しているドメインexample2.comをIP192.168.0.2のIPベースに移行する場合
...
Port 80
ServerName www.example.com
DocumentRoot /www/example
NameVirtualHost 192.168.0.1
<VirtualHost 192.168.0.1 192.168.0.2>
DocumentRoot /www/example2
ServerName www.example2.com
...
</VirtualHost>
<VirtualHost 192.168.0.1>
DocumentRoot /www/example
ServerName www.example.com
...
</VirtualHost>
参考:http://httpd.apache.org/docs/vhosts/examples.html#migrate
#exlink