[EPA2008]apache2のインストールと設定

以下では, Apache 2.2 のインストールと設定について記す. サービスとして http と https の両方を提供する.

[EPAサーバ構築ドキュメント へ戻る]

ビルドのための設定

ソースからインストールする. インストール先は apache2 のデフォルト である /usr/local/apache2 とする. この場合, configure へ --prefix の必要は無い. apache-ssl を動作させたいため --enable-ssl を, mod_rewrite を使用したいため --enable-rewrite を (gate の 登録窓口を http から https へ移動させたい), DSO (Dynamic shared object: 動的共有オブジェクト) を使用したいため --enable-so をオプションとして指定した. また, ビルド時に "Cannot use an external APR-util with the bundled APR" とエラーが生じる場合があるため, --with-included-apr オプションも指定する.

# cd /usr/local/src
# wget http://www.meisei-u.ac.jp/mirror/apache/httpd/httpd-2.2.9.tar.gz
# tar xvfz httpd-2.2.9.tar.gz
# cd httpd-2.2.4
# ./configure --enable-ssl --enable-rewrite --enable-so --with-included-apr

configure の結果は config.log や build/config_vars.mk を参照のこと.

なお, apache2 は最新バージョンをダウンロードすればよい. 最新バージョンは<URL:http://www.meisei-u.ac.jp/mirror/apache/httpd/>から確認できる.

※ 2008 年 10 月 8 日時点の最新バージョンは 2.2.9 である.

ビルドとインストール

# make
# make install

/usr/local/apache2 以下にファイルがあることを確認する.

インストールした実行ファイルへのパスの設定

インストールされた Apache のバイナリファイル群へパスを通す.

[EPA2008]パスの設定 <一般ユーザ用コマンドのパス> /usr/local/apache2/bin を追加する. (システム用コマンドも一般ユーザ用コマンドと同じ場所に インストールされているため, システム用コマンド用の設定を 別途行う必要は無い).

インストールしたマニュアルへのパスの設定

/etc/manpath.config に以下の行を追加する. 詳しくは [EPA2008]パスの設定#man 関連のパスの設定 を参照のこと.

MANDATORY_MANPATH                          /usr/local/apache2/man
MANPATH_MAP        /usr/local/apache2/bin  /usr/local/apache2/man
MANDB_MAP          /usr/local/apache2/man  /usr/local/apache2/man

モジュールの確認, 追加

インストールした apache2 で有効になっているモジュールは

# apachectl -t -D DUMP_MODULES

で確認できる. 最低限,

  • ssl_module
  • rewrite_module
  • userdir_module

を有効にしておくこと. モジュールが足りない場合, DSO(Dynamic Shared Object) を有効にしている (configure 時に --enable-so をつけている)と, 後からモジュールを追加できる. DSO が有効になっているかを確認するには

# httpd -l
Compiled in modules:
core.c
mod_authn_file.c
mod_authn_default.c
...
mod_so.c           <-- DSO モジュール

で mod_so.c が組み込まれていれば良い. DSO が有効になっていない場合には, もういちど configure からやり直し.

後からモジュールを追加する場合には apxs コマンドを使用する. 例えば mod_rewrite を追加する場合には apache のソースに行き,

# cd /usr/local/src/httpd-2.2.8/modules/mapper
# apxs -c mod_rewrite.c
# apxs -i -a -n rewrite mod_rewrite.la

とする.

設定ファイルの編集

設定ファイルは httpd 用が /usr/local/apache2/conf/httpd.conf, httpd-ssl 用が /usr/local/apache2/conf/extra/httpd-ssl.conf である. また各ユーザの public_html 以下の設定用が /usr/local/apache2/conf/extra/httpd-userdir.conf である. これらを編集する.

変更の要点は以下の通りである.

  • httpd.conf
    • HTTP デーモンを起動するユーザを www-data にする.
    • サーバ管理者 (ServerAdmin) のメールアドレスを設定
    • サーバ名 (ServerName) を設定
    • サーバのデフォルトルート (DefaultRoot) を /~epalab に設定
    • ディレクトリのインデックスファイルに index.html 以外に index.htm index.htm.en index.html.en index.htm.ja index.html.ja も追加.
    • エラーログファイルを /var/log/httpd-error.log に設定
    • アクセスログファイルを /var/log/httpd-access.log に設定
    • CGI に関する設定を変更
    • extra/httpd-vhosts.confをロード
    • extra/httpd-userdir.conf をロード
    • extra/httpd-ssl.conf をロード
    • /~gate, および /cgi-bin に対してのアクセスは HTTPS へ移動させる (参考資料 9, 10 参照).
    • ~epalab/hiki , ~itpass/hiki そして ~cps/for-steering/hiki に関しての設定を各ディレクトリごとの .htaccess で可能とする (AllowOverride ALL)
  • httpd-vhosts.conf
    • {aoe,ahs,cps}.scitec.kobe-u.ac.jp宛の接続を受ける(virtual host).
      • ドキュメントルートは/home/{aoelab,ahslab,cps}/public_htmlにする.
      • www.付きでもアクセスできるようにする.
      • 管理者メールアドレスはepaadmin _at_ ... にする.
      • http://{aoe,ahs,cps}.scitec.kobe-u.ac.jp/~gate/ 以下にアクセスされた場合には, https://epa.scitec.kobe-u.ac.jp/~gate に飛ばす.
    • epa.scitec.kobe-u.ac.jp 宛の接続のときのみ, /hiki, /~epalab/hiki, /~itpass/hiki に対してのアクセスは HTTPS へ移動させる. その際, URI のエンコードは行わない. (参考資料 9, 10, 11 参照).
  • httpd-userdir.conf
    • 所有者がマッチしなくてもシンボリックリンクの公開を許可する. (SymLinksIfOwnerMatch -> FollowSymLinks).
  • httpd-ssl.conf
    • ドキュメントルート (DocumentRoot), サーバ名 (ServerName), サーバ管理者アドレス (ServerAdmin), エラーログ (ErrorLog), アクセスログ (TransferLog) の設定.
    • ahs.scitec, aoe.scitec, cps.scitec の場合の https 接続を 設定しておく
      • 本来は 404 を返すべきなのだが, とりあえず.

オリジナルとの diff は以下の通り.

httpd.conf の diff

$ diff -u original/httpd.conf extra/httpd.conf
--- original/httpd.conf	2008-03-14 22:24:16.000000000 +0900
+++ httpd.conf	2008-08-25 16:27:07.000000000 +0900
@@ -1,3 +1,4 @@
+# -*- apache -*-
 #
 # This is the main Apache HTTP server configuration file.  It contains the
 # configuration directives that give the server its instructions.
@@ -50,7 +51,7 @@
 #
 # Example:
 # LoadModule foo_module modules/mod_foo.so
-#
+LoadModule rewrite_module     modules/mod_rewrite.so

 <IfModule !mpm_netware_module>
 <IfModule !mpm_winnt_module>
@@ -62,8 +63,8 @@
 # It is usually good practice to create a dedicated user and group for
 # running httpd, as with most system services.
 #
-User daemon
-Group daemon
+User www-data
+Group www-data

 </IfModule>
 </IfModule>
@@ -85,7 +86,7 @@
 # e-mailed.  This address appears on some server-generated pages, such
 # as error documents.  e.g. admin@your-domain.com
 #
-ServerAdmin you@example.com
+ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp

 #
 # ServerName gives the name and port that the server uses to identify itself.
@@ -94,14 +95,14 @@
 #
 # If your host doesn't have a registered DNS name, enter its IP address here.
 #
-#ServerName www.example.com:80
+ServerName epa.scitec.kobe-u.ac.jp:80

 #
 # DocumentRoot: The directory out of which you will serve your
 # documents. By default, all requests are taken from this directory, but
 # symbolic links and aliases may be used to point to other locations.
 #
-DocumentRoot "/usr/local/apache2/htdocs"
+DocumentRoot "/home/epalab/public_html"

 #
 # Each directory to which Apache has access can be configured with respect
@@ -115,7 +116,6 @@
     Options FollowSymLinks
     AllowOverride None
     Order deny,allow
-    Deny from all
 </Directory>

 #
@@ -128,7 +128,7 @@
 #
 # This should be changed to whatever you set DocumentRoot to.
 #
-<Directory "/usr/local/apache2/htdocs">
+<Directory "/home/epalab/public_html">
     #
     # Possible values for the Options directive are "None", "All",
     # or any combination of:
@@ -163,7 +163,7 @@
 # is requested.
 #
 <IfModule dir_module>
-    DirectoryIndex index.html
+    DirectoryIndex index.html index.htm index.htm.en index.html.en index.htm.ja index.html.ja
 </IfModule>

 #
@@ -183,7 +183,7 @@
 # logged here.  If you *do* define an error logfile for a <VirtualHost>
 # container, that host's errors will be logged there and not here.
 #
-ErrorLog "logs/error_log"
+ErrorLog "/var/log/httpd-error.log"

 #
 # LogLevel: Control the number of messages logged to the error_log.
@@ -212,13 +212,13 @@
     # define per-<VirtualHost> access logfiles, transactions will be
     # logged therein and *not* in this file.
     #
-    CustomLog "logs/access_log" common
+    #CustomLog "logs/access_log" common

     #
     # If you prefer a logfile with access, agent, and referer information
     # (Combined Logfile Format) you can use the following directive.
     #
-    #CustomLog "logs/access_log" combined
+    CustomLog "/var/log/httpd-access.log" combined
 </IfModule>

 <IfModule alias_module>
@@ -265,10 +265,8 @@
 # CGI directory exists, if you have that configured.
 #
 <Directory "/usr/local/apache2/cgi-bin">
-    AllowOverride None
-    Options None
-    Order allow,deny
-    Allow from all
+    AllowOverride AuthConfig Limit
+    Options ExecCGI FollowSymLinks IncludesNoExec
 </Directory>

 #
@@ -379,13 +377,13 @@
 #Include conf/extra/httpd-languages.conf

 # User home directories
-#Include conf/extra/httpd-userdir.conf
+Include conf/extra/httpd-userdir.conf

 # Real-time info on requests and configuration
 #Include conf/extra/httpd-info.conf

 # Virtual hosts
-#Include conf/extra/httpd-vhosts.conf
+Include conf/extra/httpd-vhosts.conf

 # Local access to the Apache HTTP Server Manual
 #Include conf/extra/httpd-manual.conf
@@ -397,7 +395,7 @@
 #Include conf/extra/httpd-default.conf

 # Secure (SSL/TLS) connections
-#Include conf/extra/httpd-ssl.conf
+Include conf/extra/httpd-ssl.conf
 #
 # Note: The following must must be present to support
 #       starting without SSL on platforms with no /dev/random equivalent
@@ -407,3 +405,19 @@
 SSLRandomSeed startup builtin
 SSLRandomSeed connect builtin
 </IfModule>
+
+#
+# Setting for Hiki Area
+#
+<Directory "/home/epalab/public_html/hiki">
+    AllowOverride ALL
+</Directory>
+
+<Directory "/home/itpass/public_html/hiki">
+    AllowOverride ALL
+</Directory>
+
+<Directory "/home/cps/public_html/for-steering/hiki-wheel">
+    AllowOverride ALL
+</Directory>
+

extra/httpd-userdir.conf の diff

$ diff -u original/extra/httpd-userdir.conf extra/httpd-userdir.conf
--- original/extra/httpd-userdir.conf	2008-03-14 22:24:16.000000000 +0900
+++ extra/httpd-userdir.conf	2008-08-25 16:30:58.000000000 +0900
@@ -1,3 +1,4 @@
+# -*- apache -*- 
 # Settings for user home directories
 #
 # Required module: mod_userdir
@@ -15,7 +16,7 @@
 #
 <Directory "/home/*/public_html">
     AllowOverride FileInfo AuthConfig Limit Indexes
-    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+    Options MultiViews Indexes FollowSymLinks IncludesNoExec
     <Limit GET POST OPTIONS>
         Order allow,deny
         Allow from all

extra/httpd-ssl.conf の diff

$ diff -u original/extra/httpd-ssl.conf extra/httpd-ssl.conf
--- original/extra/httpd-ssl.conf	2008-03-14 22:24:16.000000000 +0900
+++ extra/httpd-ssl.conf	2008-08-25 16:26:50.000000000 +0900
@@ -1,3 +1,4 @@
+# -*- apache -*-
 #
 # This is the Apache server configuration file providing SSL support.
 # It contains the configuration directives to instruct the server how to
@@ -71,23 +72,25 @@
 ## SSL Virtual Host Context
 ##

-<VirtualHost _default_:443>
+NameVirtualHost *:443

+<VirtualHost *:443>
 #   General setup for the virtual host
-DocumentRoot "/usr/local/apache2/htdocs"
-ServerName www.example.com:443
-ServerAdmin you@example.com
-ErrorLog "/usr/local/apache2/logs/error_log"
-TransferLog "/usr/local/apache2/logs/access_log"
+  DocumentRoot "/home/epalab/public_html"
+  ServerName epa.scitec.kobe-u.ac.jp:443
+  ServerAlias www.epa.scitec.kobe-u.ac.jp:443
+  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
+  ErrorLog /var/log/httpd-ssl-error.log
+  TransferLog /var/log/httpd-ssl-access.log

 #   SSL Engine Switch:
 #   Enable/Disable SSL for this virtual host.
-SSLEngine on
+  SSLEngine on

 #   SSL Cipher Suite:
 #   List the ciphers that the client is permitted to negotiate.
 #   See the mod_ssl documentation for a complete list.
-SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
+  SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

 #   Server Certificate:
 #   Point SSLCertificateFile at a PEM encoded certificate.  If
@@ -96,7 +99,7 @@
 #   in mind that if you have both an RSA and a DSA certificate you
 #   can configure both in parallel (to also allow the use of DSA
 #   ciphers, etc.)
-SSLCertificateFile "/usr/local/apache2/conf/server.crt"
+  SSLCertificateFile "/usr/local/apache2/conf/server.crt"
 #SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"

 #   Server Private Key:
@@ -104,7 +107,7 @@
 #   directive to point at the key file.  Keep in mind that if
 #   you've both a RSA and a DSA private key you can configure
 #   both in parallel (to also allow the use of DSA ciphers, etc.)
-SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
+  SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
 #SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"

 #   Server Certificate Chain:
@@ -187,12 +190,12 @@
 #     This enables optimized SSL connection renegotiation handling when SSL
 #     directives are used in per-directory context. 
 #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
-<FilesMatch "\.(cgi|shtml|phtml|php)$">
+  <FilesMatch "\.(cgi|shtml|phtml|php)$">
     SSLOptions +StdEnvVars
-</FilesMatch>
-<Directory "/usr/local/apache2/cgi-bin">
+  </FilesMatch>
+  <Directory "/usr/local/apache2/cgi-bin">
     SSLOptions +StdEnvVars
-</Directory>
+  </Directory>

 #   SSL Protocol Adjustments:
 #   The safe and default but still SSL/TLS standard compliant shutdown
@@ -218,14 +221,38 @@
 #   Similarly, one has to force some clients to use HTTP/1.0 to workaround
 #   their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
 #   "force-response-1.0" for this.
-BrowserMatch ".*MSIE.*" \
-         nokeepalive ssl-unclean-shutdown \
-         downgrade-1.0 force-response-1.0
+  BrowserMatch ".*MSIE.*" \
+           nokeepalive ssl-unclean-shutdown \
+           downgrade-1.0 force-response-1.0

 #   Per-Server Logging:
 #   The home of a custom SSL log file. Use this when you want a
 #   compact non-error SSL logfile on a virtual host basis.
-CustomLog "/usr/local/apache2/logs/ssl_request_log" \
-          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
+  CustomLog "/usr/local/apache2/logs/ssl_request_log" \
+            "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

-</VirtualHost>                                  
+</VirtualHost>
+
+<VirtualHost *:443>
+  DocumentRoot "/home/aoelab/public_html"
+  ServerName aoe.scitec.kobe-u.ac.jp:443
+  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
+  ErrorLog /var/log/httpd-ssl-error.log
+  TransferLog /var/log/httpd-ssl-access.log
+</VirtualHost>
+
+<VirtualHost *:443>
+  DocumentRoot "/home/ahslab/public_html"
+  ServerName ahs.scitec.kobe-u.ac.jp:443
+  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
+  ErrorLog /var/log/httpd-ssl-error.log
+  TransferLog /var/log/httpd-ssl-access.log
+</VirtualHost>
+
+<VirtualHost *:443>
+  DocumentRoot "/home/cps/public_html"
+  ServerName cps.scitec.kobe-u.ac.jp:443
+  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
+  ErrorLog /var/log/httpd-ssl-error.log
+  TransferLog /var/log/httpd-ssl-access.log
+</VirtualHost>

extra/httpd-vhost.conf の diff

diff -u original/extra/httpd-vhost.conf extra/httpd-vhost.conf  
-- original/extra/httpd-vhosts.conf	2008-03-14 22:24:16.000000000 +0900
++ extra/httpd-vhosts.conf	2008-08-25 16:27:27.000000000 +0900
@ -1,3 +1,4 @@
# -*- apache -*-
#
# Virtual Hosts
#
@ -18,28 +19,85 @@
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
  DocumentRoot "/home/epalab/public_html"
  ServerName epa.scitec.kobe-u.ac.jp
  ServerAlias www.epa.scitec.kobe-u.ac.jp
  ErrorLog /var/log/httpd-error.log
  CustomLog /var/log/httpd-access.log combined

  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteLog "/var/log/httpd-rewrite.log"
    RewriteLogLevel 0
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/hiki/(.*)?$ https://epa.scitec.kobe-u.ac.jp/hiki/$1 [L,R]
    # ---- hiki
    RewriteRule ^/~epalab/hiki/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~epalab/hiki/$1 [L,R,NE]
    RewriteRule ^/~itpass/hiki/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~itpass/hiki/$1 [L,R,NE]
    # ---- gate
    RewriteRule ^/~gate/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
    RewriteRule ^/cgi-bin/(.*)?$ https://epa.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
  </IfModule>
</VirtualHost>

# ---- aoelab ----
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/usr/local/apache2/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
  DocumentRoot "/home/aoelab/public_html"
  ServerName aoe.scitec.kobe-u.ac.jp
  ServerAlias www.aoe.scitec.kobe-u.ac.jp
  ErrorLog /var/log/httpd-error.log
  CustomLog /var/log/httpd-access.log combined
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteLog "/var/log/httpd-rewrite.log"
    RewriteLogLevel 0
    RewriteCond %{SERVER_PORT} !^443$
    # ---- hiki
    RewriteRule ^/hiki/(.*)?$ https://epa.scitec.kobe-u.ac.jp/hiki/$1 [L,R]
    # ---- gate
    RewriteRule ^/~gate/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
    RewriteRule ^/cgi-bin/(.*)?$ https://epa.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
 </IfModule>
</VirtualHost>

# ---- ahslab ----
<VirtualHost *:80>
  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
  DocumentRoot "/home/ahslab/public_html"
  ServerName ahs.scitec.kobe-u.ac.jp
  ServerAlias www.ahs.scitec.kobe-u.ac.jp
  ErrorLog /var/log/httpd-error.log
  CustomLog /var/log/httpd-access.log combined
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteLog "/var/log/httpd-rewrite.log"
    RewriteLogLevel 0
    RewriteCond %{SERVER_PORT} !^443$
    # ---- gate
    RewriteRule ^/~gate/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
    RewriteRule ^/cgi-bin/(.*)?$ https://epa.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
  </IfModule>
</VirtualHost>

# ---- cps ----
<VirtualHost *:80>
  ServerAdmin epaadmin_at_epa.scitec.kobe-u.ac.jp
  DocumentRoot "/home/cps/public_html"
  ServerName cps.scitec.kobe-u.ac.jp
  ErrorLog /var/log/httpd-error.log
  CustomLog /var/log/httpd-access.log combined
  <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteLog "/var/log/httpd-rewrite.log"
    RewriteLogLevel 0
    RewriteCond %{SERVER_PORT} !^443$
    # ---- gate
    RewriteRule ^/~gate/(.*)?$ https://epa.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
    RewriteRule ^/cgi-bin/(.*)?$ https://epa.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
  </IfModule>
</VirtualHost>

ログローテートの設定

/etc/logrotate.conf を編集して圧縮オプションを追加する. (compressのコ メントアウトを外す).

/etc/logrotate.d/ 以下に apache2 というファイルを置き, 以下の 内容を書き込む.

/var/log/httpd-access.log {
    missingok
    rotate 12
    postrotate
        /usr/bin/killall -HUP httpd 2> /dev/null || true
    endscript
}

/var/log/httpd-error.log {
    missingok
    rotate 12
    postrotate
        /usr/bin/killall -HUP httpd 2> /dev/null || true
    endscript
}

/var/log/httpd-ssl-access.log {
    missingok
    rotate 12
    postrotate
        /usr/bin/killall -HUP httpd 2> /dev/null || true
    endscript
}

/var/log/httpd-ssl-error.log {
    missingok
    rotate 12
    postrotate
        /usr/bin/killall -HUP httpd 2> /dev/null || true
    endscript
}

SSL 用の証明書の作成

openssl の設定を変更

# vi /etc/ssl/openssl.cnf

[usr_cert] セクションの
nsCertType=server のコメントを外す

[v3_ca] セクションの
nsCertType=sslCA,emailCA のコメントを外す.

証明書を作成する.

# cd /usr/local/apache2/conf
# /usr/lib/ssl/misc/CA.sh -newca

CA certificate filename: (空で Enter)

Enter PEM pass phrase: (適当な文字列入力. 後で消す)

Country Name (2 letter code) [AU]: JP
State or Province Name [Some-State]: Hyogo
Locality Name (eg, city) []: Kobe
Organization Name (eg, company) []: Kobe University
Organizational Unit Name (eg, section) []: EPA lab.
Common Name: epa.scitec.kobe-u.ac.jp
Email Address: epaadmin_at_epa.scitec.kobe-u.ac.jp
A challenge password: (空で Enter)
A optional company name: (空で Enter)

Enter pass phrase for ./demoCA/private/./cakey.pem: (適当な文字列入力. 後で消す)

パスフレーズを消す. 問われるパスフレーズには空文字を与える.

# openssl rsa -in ./demoCA/private/cakey.pem -out ./demoCA/private/cakey.pem

証明書の作成.

# openssl x509 -in ./demoCA/cacert.pem -out ./demoCA/server.crt

ブラウザに登録されるバイナリ DER フォーマットで記述された ファイルの作成.

# openssl x509 -inform pem -in ./demoCA/cacert.pem -outform der -out ./demoCA/ca.der

これらの作業により, demoCA 以下に server.crt と ca.der が作成される. これらのファイルをカレントディレクトリである /usr/local/apache2/conf 以下にコピーする.

# cp demoCA/server.crt .
# cp demoCA/ca.der .

server.key を demoCA/private/cakey.pem からコピーする.

# cp demoCA/private/cakey.pem ./server.key

これで鍵の作成は完了である.

動作チェック

apache は /usr/local/apache2/bin/apachectl で起動/停止する. 以下のコマンドで apache を起動する.

# /usr/local/apache2/bin/apachectl -k start

停止するには以下のようにすると良い

# /usr/local/apache2/bin/apachectl -k graceful-stop

起動スクリプトを用意する

サーバの起動時に自動的に起動させるため, apache2 の起動スクリプト を用意する.

Debian の apache パッケージに含まれる/etc/init.d/apache を元に 起動スクリプトを apache2 用に多少書き換えたものが apache2 から入手できる. このファイルを /etc/init.d/apache2 にコピーし, 以下のようにパーミッションを設定する.

# wget http://epa.scitec.kobe-u.ac.jp/~itpass/epa/apache/apache2
# cp apache2 /etc/init.d/
# chown root:root /etc/init.d/apache2
# chmod 755 /etc/init.d/apache2

なお, この実行ファイル apache2 には冒頭部に httpd.conf や apachectl ファイルのパスを設定する箇所がある. インストールの場所が変更される場合にはこれも変更すること.

ランレベルごとに apache2 の動作を設定する.

# update-rc.d apache2 defaults

サーバを再起動し, 起動時に apache が起動することを確認する.

補足事項

ロード済みモジュールの表示

以下のように httpd コマンドに -M オプションをつけて実行することで, 静的にロードされたモジュールと動的にロードされたモジュールの両方が 表示される.

$ /usr/local/apache2/bin/httpd -M

以下のように -l オプションを指定すると, 組み込みモジュールのリストが 表示できる.

$ /usr/local/apache2/bin/httpd -l

参考資料

  1. 平衡点 -- equilibrium point -- > [comp][debian] apache2 + ssl
  2. EP WWW サーバ構築ログ (ログローテートに関して)
  3. apxsでapacheにモジュールを追加する
  4. @IT > Linux Square > Apacheの基本インストール
  5. @IT > Linux Square > Apache 2.2でWebサイトをパフォーマンスアップ!
  6. SSL-Webサーバー-CA公開カギを準備する
  7. OpenSSLでの自己認証局(CA)と自己証明書の作成
  8. apache2.2 インストール
  9. パソコンおやじ -- HTTPでアクセスした時、自動的にHTTPSにrewriteする方法
  10. SquirrelMailの導入
  11. Apache 2.0 Documentation -- mod_rewrite

[EPAサーバ構築ドキュメント へ戻る]