IT pass HikiWiki - [ITPASS2010]apache2のインストールと設定 Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

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

{{toc_here}}

[((<ITPASSサーバ構築ドキュメント>)) へ戻る]

== ビルドのための設定

ソースからインストールする. インストール先は 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.16.tar.gz
  # tar xvfz httpd-2.2.16.tar.gz
  # cd httpd-2.2.16
  # ./configure --enable-ssl --enable-rewrite --enable-so --with-included-apr

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

apache の最新バージョンは((<URL:http://www.meisei-u.ac.jp/mirror/apache/httpd/>))から確認できる.

※ 2010 年 10 月 5 日時点の最新バージョンは 2.2.16 である.

== ビルドとインストール

  # make
  # make install

/usr/local/apache2 以下に複数のディレクトリが作成されていることを確認する.

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

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

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

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

/etc/manpath.config に以下の行を追加する.
詳しくは ((<[ITPASS2010]パスの設定#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.16/modules/mapper
  # apxs -c mod_rewrite.c
  # apxs -i -a -n rewrite mod_rewrite.la

とする.

== 設定ファイルの編集

各種設定ファイルは以下のとおり.

(要確認) 以下の設定作業の中に, cps グループについて設定を行う項目が
いくつかあるが, cps 関連は別サーバに移行されたため, グループとしては
itpass サーバ内に存在しているが, cps グループ用の各種設定を行うのかは
設定前に上の人に確認をとること.

  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) を /~itpass に設定
  * ディレクトリのインデックスファイルに 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 へ移動させる
    (((<参考資料|URL:#参考資料>)) 9, 10 参照).
  * 以下の 5 つの Hiki 領域
    ~epalab/hiki , ~itpass/hiki, ~itpass/hiki-secret,
    ~tansaku/hiki, ~cps/for-steering/hiki に関する設定を,
    各領域毎の .htaccess により可能にする

    (AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks).

* httpd-vhosts.conf
  * {epa,aoe,cps}.scitec.kobe-u.ac.jp 宛の接続を受ける(virtual host).
    * ドキュメントルートは /home/{epalab,aoelab,cps}/public_html にする.
    * 管理者メールアドレスは itpadmin _at_ ... にする.
    * http://{epa,aoe,cps}.scitec.kobe-u.ac.jp/~gate/
      以下にアクセスされた場合には,
      https://itpass.scitec.kobe-u.ac.jp/~gate に飛ばす.
  * itpass.scitec.kobe-u.ac.jp 宛の接続のときのみ,
    /hiki, /~epalab/hiki, /~itpass/hiki に対してのアクセスは
    HTTPS へ移動させる. その際, URI のエンコードは行わない.
    (((<参考資料|URL:#参考資料>)) 9, 10, 11 参照).

* httpd-userdir.conf
  * 所有者がマッチしなくてもシンボリックリンクの公開を許可する.
    (SymLinksIfOwnerMatch -> FollowSymLinks).

* httpd-ssl.conf
  * ドキュメントルート (DocumentRoot),
    サーバ名 (ServerName),
    サーバ管理者アドレス (ServerAdmin),
    エラーログ (ErrorLog),
    アクセスログ (TransferLog) の設定.
  * epa.scitec, aoe.scitec, cps.scitec の場合の https 接続を設定しておく
    * 本来は 404 を返すべきなのだが,  とりあえず.

オリジナルとの diff は以下の通り(以下の diff 結果を参考に実際にファイルを書き換える).

(注意)
* 以下の作業を行う前に管理者用メールアドレスを必ず確認のこと.
  以下の作業を行ったのち, アドレスが違っていたら, この作業はすべてやり直しとなる.
* 設定ファイルのところどころにメールアドレスを指定する項目がある.
  以下の diff では "_at_" となっているが, 実際にファイルを書き換える際にはすべて "@" に読み替えて書き換えること.


=== httpd.conf の diff

$ diff -u original/httpd.conf httpd.conf
--- original/httpd.conf 2010-10-05 15:39:10.000000000 +0900
+++ httpd.conf  2010-11-02 21:18:21.000000000 +0900
@@ -1,4 +1,3 @@
-#
  # This is the main Apache HTTP server configuration file.  It contains the
  # configuration directives that give the server its instructions.
  # See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
@@ -50,6 +49,7 @@
  #
  # Example:
  # LoadModule foo_module modules/mod_foo.so
+# LoadModule rewrite_module modules/mod_rewrite.so
  #

  <IfModule !mpm_netware_module>
@@ -62,8 +62,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 +85,7 @@
  # e-mailed.  This address appears on some server-generated pages, such
  # as error documents.  e.g. admin_at_your-domain.com
  #
-ServerAdmin you_at_example.com
+ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp

  #
  # ServerName gives the name and port that the server uses to identify itself.
@@ -94,15 +94,14 @@
  #
  # If your host doesn't have a registered DNS name, enter its IP address here.
  #
-#ServerName www.example.com:80
+ServerName itpass.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/itpass/public_html"
  #
  # Each directory to which Apache has access can be configured with respect
  # to which services and features are allowed and/or disabled in that
@@ -115,7 +114,7 @@
      Options FollowSymLinks
      AllowOverride None
      Order deny,allow
-    Deny from all
+
  </Directory>

  #
@@ -128,7 +127,7 @@
  #
  # This should be changed to whatever you set DocumentRoot to.
  #
-<Directory "/usr/local/apache2/htdocs">
+<Directory "/home/itpass/public_html">
      #
      # Possible values for the Options directive are "None", "All",
      # or any combination of:
@@ -163,7 +162,8 @@
  # 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_org" combined
  </IfModule>

  <IfModule alias_module>
@@ -265,10 +265,11 @@
  # 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>

  #
@@ -315,7 +316,7 @@
      # To use CGI scripts outside of ScriptAliased directories:
      # (You will also need to add "ExecCGI" to the "Options" directive.)
      #
-    #AddHandler cgi-script .cgi
+    AddHandler cgi-script .cgi .rb

      # For type maps (negotiated resources):
      #AddHandler type-map var
@@ -379,13 +380,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 +398,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 +408,67 @@
  SSLRandomSeed startup builtin
  SSLRandomSeed connect builtin
  </IfModule>
+
+#
+# Setting for Hiki Area
+#
+<Directory "/home/epalab/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/itpass/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/itpass/public_html/hiki-secret">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/cps/public_html/for-steering/hiki-wheel">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+
+<Directory "/home/tansaku/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/uwabami/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/gpgpu/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/gridcomp/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/ayako/public_html/suzuhiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/pschool/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/bldg3/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/fourtran/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>


=== extra/httpd-ssl.conf の diff

$ diff -u original/extra/httpd-ssl.conf extra/httpd-ssl.conf
--- original/extra/httpd-ssl.conf       2010-10-05 15:39:11.000000000 +0900
+++ extra/httpd-ssl.conf        2010-10-19 13:27:48.000000000 +0900
@@ -71,14 +71,15 @@
  ## 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_at_example.com
-ErrorLog "/usr/local/apache2/logs/error_log"
-TransferLog "/usr/local/apache2/logs/access_log"
+DocumentRoot "/home/itpass/public_html"
+ServerName itpass.scitec.kobe-u.ac.jp:443
+ServerAdmin itpadmin_at_itpass.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.
@@ -96,7 +97,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/ca/itpass/server.crt"
  #SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"

  #   Server Private Key:
@@ -104,7 +105,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/ca/itpass/server.key"
  #SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"

  #   Server Certificate Chain:
@@ -114,7 +115,7 @@
  #   the referenced file can be the same as SSLCertificateFile
  #   when the CA certificates are directly appended to the server
  #   certificate for convinience.
-#SSLCertificateChainFile "/usr/local/apache2/conf/server-ca.crt"
+#SSLCertificateChainFile "/usr/local/apache2/conf/server.crt"

  #   Certificate Authority (CA):
  #   Set the CA certificate verification path where to find CA
@@ -228,4 +229,41 @@
  CustomLog "/usr/local/apache2/logs/ssl_request_log" \
            "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

+</VirtualHost>
+
+<VirtualHost *:443>
+ DocumentRoot "/home/aoelab/public_html"
+ ServerName aoe.scitec.kobe-u.ac.jp:443
+ ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp
+ ErrorLog /var/log/httpd-ssl-error.log
+ TransferLog /var/log/httpd-ssl-access.log
+ SSLEngine on
+ SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
+ SSLCertificateFile "/usr/local/apache2/conf/ca/aoe/server.crt"
+ SSLCertificateKeyFile "/usr/local/apache2/conf/ca/aoe/server.key"
+</VirtualHost>
+
+<VirtualHost *:443>
+ DocumentRoot "/home/cps/public_html"
+ ServerName cps.scitec.kobe-u.ac.jp:443
+ ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp
+ ErrorLog /var/log/httpd-ssl-error.log
+ TransferLog /var/log/httpd-ssl-access.log
+ SSLEngine on
+ SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
+ SSLCertificateFile "/usr/local/apache2/conf/ca/cps/server.crt"
+ SSLCertificateKeyFile "/usr/local/apache2/conf/ca/cps/server.key"
+</VirtualHost>
+
+
+<VirtualHost *:443>
+ DocumentRoot "/home/epalab/public_html"
+ ServerName epa.scitec.kobe-u.ac.jp:443
+ ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp
+ ErrorLog /var/log/httpd-ssl-error.log
+ TransferLog /var/log/httpd-ssl-access.log
+ SSLEngine on
+ SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
+ SSLCertificateFile "/usr/local/apache2/conf/ca/epa/server.crt"
+ SSLCertificateKeyFile "/usr/local/apache2/conf/ca/epa/server.key"
  </VirtualHost>


=== extra/httpd-vhost.conf の diff

$ diff -u original/extra/httpd-vhosts.conf extra/httpd-v
hosts.conf
--- original/extra/httpd-vhosts.conf    2010-10-05 15:39:11.000000000 +0900
+++ extra/httpd-vhosts.conf     2010-10-29 15:51:28.000000000 +0900
@@ -25,21 +25,89 @@
  # match a ServerName or ServerAlias in any <VirtualHost> block.
  #
  <VirtualHost *:80>
-    ServerAdmin webmaster_at_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 itpadmin_at_itpass.scitec.kobe-u.ac.jp
+    DocumentRoot "/home/itpass/public_html"
+    ServerName itpass.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://itpass.scitec.kobe-u.ac.jp/hiki/$1 [L,R,NE]
+      RewriteRule ^/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/hiki-secret/$1 [L,R,NE]
+      # ---- hiki
+      RewriteRule ^/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/hiki/$1 [L,R,NE]
+      RewriteRule ^/~bldg3/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~bldg3/hiki/$1 [L,R,NE]
+      RewriteRule ^/~epalab/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~epalab/hiki/$1 [L,R,NE]
+      RewriteRule ^/~itpass/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~itpass/hiki/$1 [L,R,NE]
+      RewriteRule ^/~itpass/hiki-secret/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~itpass/hiki-secret/$1 [L,R,NE]
+      # ---- gate
+      RewriteRule ^/~gate/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
+      RewriteRule ^/cgi-bin/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
+    </IfModule>
+</VirtualHost>
+
+# ---- aoelab ----
+<VirtualHost *:80>
+    ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp
+    DocumentRoot "/home/aoelab/public_html"
+    ServerName 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://itpass.scitec.kobe-u.ac.jp/hiki/$1 [L,R]
+      # ---- gate
+      RewriteRule ^/~gate/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
+      RewriteRule ^/cgi-bin/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
+    </IfModule>
  </VirtualHost>

+# ---- cps ----
  <VirtualHost *:80>
-    ServerAdmin webmaster_at_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  itpadmin_at_itpass.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$
+      # ---- hiki
+      RewriteRule ^/hiki/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/hiki/$1 [L,R]
+      # ---- gate
+      RewriteRule ^/~gate/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
+      RewriteRule ^/cgi-bin/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
+    </IfModule>
  </VirtualHost>


+# ---- epalab ----
+<VirtualHost *:80>
+    ServerAdmin itpadmin_at_itpass.scitec.kobe-u.ac.jp
+    DocumentRoot "/home/epalab/public_html"
+    ServerName 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$
+      # ---- hiki
+      RewriteRule ^/hiki/(.*)?$ https://epa.scitec.kobe-u.ac.jp/hiki/$1 [L,R,NE]
+      # ---- gate
+      RewriteRule ^/~gate/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/~gate/$1 [L,R,NE]
+      RewriteRule ^/cgi-bin/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
+    </IfModule>
+</VirtualHost>


=== extra/httpd-userdir.conf の diff
    
$ diff -u original/extra/httpd-userdir.conf extra/httpd-userdir.conf
--- original/extra/httpd-userdir.conf   2010-10-05 15:39:11.000000000 +0900
+++ extra/httpd-userdir.conf    2010-10-05 17:18:43.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
@@ -24,5 +25,12 @@
          Order deny,allow
          Deny from all
      </LimitExcept>
+    <IfModule negotiation_module>
+        AddLanguage ja .ja
+        AddLanguage ja-JP .ja
+        AddLanguage en .en
+        LanguagePriority en ja
+        ForceLanguagePriority Prefer Fallback
+    </IfModule>
  </Directory>


== ログローテートの設定

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

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

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

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

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

    /var/log/httpd-ssl-error.log {
        missingok
        weekly
        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 のコメントアウトを外す.

=== プライベート CA の作成

まず, apache の config ファイルに入り, 次のように証明書を格納するディレクトリを作成する.

  # cd /usr/local/apache2/conf
  # mkdir ca
  # cd ./ca/
  # mkdir {itpass,epa,aoe,cps のそれぞれの名称で作成}

以下の作業は ServerName : itpass.scitec.kobe-u.ac.jp, epa.scitec.kobe-u.ac.jp, aoe.scitec.kobe-u.ac.jp, cps.scitec.kobe-u.ac.jp
のそれぞれについて行う. サーバ名を適宜読み替え, 4 回実行する.

  # /usr/lib/ssl/misc/CA.pl -newca
  CA certificate filename (or enter to create)
  (空で Enter)

  Enter PEM pass phrase: (適当な文字列入力)

  Country Name (2 letter code) [AU]: JP
  State or Province Name (full name) [Some-State]: Hyogo
  Locality Name (eg, city) []: Kobe
  Organization Name (eg, company) [Internet Widgits Pty Ltd]: Private_CA
  Organizational Unit Name (eg, section) []: Private_CA
  Common Name (eg, YOUR name) : Private_CA
  Email Address: itpadmin_at_itpass.scitec.kobe-u.ac.jp
  A challenge password: (空で Enter)
  A optional company name: (空で Enter)

  Enter pass phrase for ./demoCA/private/./cakey.pem: (先と同じパスフレーズ)

この作業で以下のようなディレクトリ構造になったことを確認.

/usr/local/apache2/conf
                    |
                    └ demoCA [ 各種証明書等のルートディレクトリ ]
                        |
                        ├ certs [ 証明書等のディレクトリ(バックアップに利用) ]
                        |
                        ├ crl [ 破棄証明書一覧用のディレクトリ ]
                        |
                        ├ newcerts [ クライアント証明書(sireal追番)のディレクトリ ]
                        |  |
                        |  ├ xxxxx..pem [ クライアント証明書 ]
                        |  |    :
                        |  └ xxxxx..pem [ クライアント証明書 ]
                        |
                        ├ private [ CA用の秘密鍵用ディレクトリ ]
                        |  |
                        |  └ cakey.pem [ CA用の秘密鍵 ]
                        |
                        ├ cacert.pem [ CA用の証明書 ]
                        ├ index.txt     [ クライアント証明書用DB ]
                        └ serial [ クライアント証明書用シリアル ]

以下で, サーバ用 CA 証明書の作成

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

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

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

サーバ用秘密鍵の作成

# /usr/lib/ssl/misc/CA.pl -newreq-nodes

  Country Name (2 letter code) [AU]: JP
  State or Province Name (full name) [Some-State]: Hyogo
  Locality Name (eg, city) []: Kobe
  Organization Name (eg, company) [Internet Widgits Pty Ltd]: Kobe University
  Organizational Unit Name (eg, section) []: ITPASS (他に "EPA lab.", "AOE lab.", "CPS" として登録)
  Common Name (eg, YOUR name) : itpass.scitec.kobe-u.ac.jp (ここは itpass の他に, epa, aoe, cps の分をそれぞれ作成する)
  Email Address: itpadmin_at_itpass.scitec.kobe-u.ac.jp
  A challenge password: (空で Enter)
  A optional company name: (空で Enter)

サーバ用証明書の作成

# /usr/lib/ssl/misc/CA.pl -sign
...
Enter pass phrase for ./demoCA/private/cakey.pem: (さきほどのパスフレーズを入力)
...
Sign the certificate? [y/n]: y[Enter]
1 out of 1 certificate requests certified, commit? [y/n] y[Enter]

サーバ証明書を crt ファイルに書き出す.

# openssl x509 -in newcert.pem -out server.crt

これらの作業により, demoCA 以下に ca.der が, カレントディレクトリに server.crt, newkey.pem が作成される.
これらのファイルを証明書を格納するために作成した ca ディレクトリ以下に格納する.

  # mv server.crt ca/itpass(この名称は適宜読み替え)/
  # mv newkey.pem ca/itpass(この名称は適宜読み替え)/server.key
  # mv demoCA/ca.der ca/itpass(この名称は適宜読み替え)/

最後に demoCA ディレクトリ以下を削除する.

  # rm -r demoCA/

これで鍵の作成は完了である. ここまでを itpass, epa, aoe, cps のそれぞれについて計 4 回行う.
上までの作業で ServerName の部分は各証明書の作成時に適宜読み替えること.


== 動作チェック

apache を起動する前に, ドキュメントルートとなるディレクトリを作成しておく. 具体的には, /home/ 以下に itpass/, epalab/, aoelab/, cps/ という 4 つのディレクトリを作り, さらにそれぞれのディレクトリ内に public_html/ というディレクトリを作る.

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

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

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

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

起動したかどうかは,

  $ ps aux

などで画面左端に www-data 表示されていれば, 起動しているということがわかる.

また, apache の設定ファイルに記述されているエラーログの記録場所に存在するログファイルなどを確認し, エラーが出ていなければOK.

ホームディレクトリに任意のディレクトリを作成し, その中に public_html ディレクトリを作成. その中に適当なテキストファイルを作成後,
ブラウザで当該 URL にアクセスし, そのテキストファイルの内容が正常に表示されていることを確認する.
URL に記述するとき, "http://..." と "https://..." の両方に関して行ってみる.

さらに, サーバ移行後に, ブラウザで, https://{} の {} 部分を epa, itpass で書き換えた URL を指定し, サーバ証明書の詳細を表示させたとき, ちゃんと epa, itpass のそれぞれをサーバ名とする証明書を表示しているかを確認する.


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

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

Debian の apache パッケージに含まれる/etc/init.d/apache を元に
起動スクリプトを apache2 用に多少書き換えたものが
((<apache2|URL:../server/2010/apache/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

  update-rc.d: warning: /etc/init.d/apache2 missing LSB information
  update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
   Adding system startup for /etc/init.d/apache2 ...
     /etc/rc0.d/K20apache2 -> ../init.d/apache2
     /etc/rc1.d/K20apache2 -> ../init.d/apache2
     /etc/rc6.d/K20apache2 -> ../init.d/apache2
     /etc/rc2.d/S20apache2 -> ../init.d/apache2
     /etc/rc3.d/S20apache2 -> ../init.d/apache2
     /etc/rc4.d/S20apache2 -> ../init.d/apache2
     /etc/rc5.d/S20apache2 -> ../init.d/apache2


== 補足事項

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

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

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

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

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

== 参考資料

(1) ((<"平衡点 -- equilibrium point -- > [comp][debian] apache2 + ssl"|URL:http://d.hatena.ne.jp/sasakyh/20070427#p1>))

(2) ((<EP WWW サーバ構築ログ (ログローテートに関して)|URL:http://www.ep.sci.hokudai.ac.jp/~epwww/dvlop/apache2.html>))
  
(3) ((<apxsでapacheにモジュールを追加する|URL:http://kazmax.zpp.jp/apache/apache3.html>))

(4) ((<@IT > Linux Square > Apacheの基本インストール|URL:http://www.atmarkit.co.jp/flinux/rensai/apache03/apache03e.html>))

(5) ((<@IT > Linux Square > Apache 2.2でWebサイトをパフォーマンスアップ!|URL:http://www.atmarkit.co.jp/flinux/special/apache22/apache01.html>))

(6) ((<SSL-Webサーバー-CA公開カギを準備する|URL:http://safe-linux.homeip.net/web/linux-ssl_web-07.html>))

(7) ((<OpenSSLでの自己認証局(CA)と自己証明書の作成|URL:http://www015.upp.so-net.ne.jp/unixlife/practical/openssl.html>))

(8) ((<apache2.2 インストール|URL:http://kazmax.zpp.jp/apache/apache.html>))

(9) ((<パソコンおやじ -- HTTPでアクセスした時、自動的にHTTPSにrewriteする方法|URL:http://www.aconus.com/~oyaji/tips/apache_tips1.htm>))

(10) ((<SquirrelMailの導入|URL:http://www.aconus.com/~oyaji/mail2/squirrelmail.htm>))

(11) ((<Apache 2.0 Documentation -- mod_rewrite|URL:http://httpd.apache.org/docs/2.0/ja/mod/mod_rewrite.html>))

(12) ((<サーバの実験室 Slackware -- SSL(サーバ認証)|URL:http://www.nina.jp/server/slackware/httpd/httpd-ssl.html>))

[((<ITPASSサーバ構築ドキュメント>)) へ戻る]