[ITPASS2022]Apache のインストールと設定

Apache のインストールと設定

最新バージョンの状況に合わせて作業内容を見直しながら行う.

ビルドのための設定

  • PCRE をインストールする.

    # apt install libpcre3 libpcre3-dev
  • expat のインストール
    • インストールの途中で expat.h が必要となるので (apr-util の make でエラーが出る), 手動で expat.h を含むパッケージを取得する.
    • <URL:https://sourceforge.net/projects/expat/files/expat/2.4.9/expat-2.4.9.tar.gz/download> より expat-2.4.9.tar.gz を手元の PC 等にダウンロードし, scp で tako に転送する. (tako から wget でダウンロードできないように見えるので.)

      $ scp expat-2.4.9.tar.gz hoge@***.**.***.**:~/     ! ローカルマシンから tako への転送. hoge はユーザー名
      
      # cp expat-2.4.9.tar.gz /usr/local/src
      # tar xvf expat-2.4.9.tar.gz
      # cd expat-2.4.9
      # ./configure --prefix=/usr/local/expat
      # make
      # make install
  • ソースを取得・展開

    ※ 2022 年 10 月 25 日時点の最新バージョンは 2.4.54 である.

  • apr, apr-util のインストール
    • インストール先と configure の際につけるオプションは以下の通り.

      # tar xzf apr-1.7.0.tar.gz
      # cd apr-1.7.0
      #  ./configure
      # make
      # make install
      
      # cd /usr/local/src
      # tar xzf apr-util-1.6.1.tar.gz 
      # cd apr-util-1.6.1
      # ./configure --with-apr=/usr/local/apr --with-expat=/usr/local/expat
      # make
      # make install
  • httpd のインストール

    • configure オプション (: 目的)

      • --enable-ssl (: apache-ssl を動作させるため)
      • --enable-rewrite (: mod_rewrite を使用するため)
        • gate の登録窓口を http から https へ移動させたい
      • --enable-so (: DSO (Dynamic shared object: 動的共有オブジェクト) を使用するため)
      • --with-included-apr (: ビルド時に "Cannot use an external APR-util with the bundled APR" とエラーが生じる場合があるため)
      # cd /usr/local/src
      # tar xvzf httpd-2.4.54.tar.gz
      # cd httpd-2.4.54
    # ./configure --enable-ssl --enable-rewrite --enable-so --with-apr=/usr/local/apr
    • なお, インストール先は /usr/local/apache2 (apache2 のデフォルト)
      • configure の際に --prefix の設定は不要
    • configure の結果は config.log を参照し, 問題ないか確認する.

ビルドとインストール

# make
# make install
  • /usr/local/apache2 の下に以下のディレクトリが作成されていることを確認する.
XXXX@xxx-itpass:/usr/local/apache2# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

実行ファイルへのパスの設定

  • インストールされた Apache のバイナリファイル群へパスを通す.
    • [ITPASS2020]パスの設定 <一般ユーザ用コマンドのパス> <システム管理用コマンドのパス> の両方に /usr/local/apache2/bin を追加する. (システム管理用コマンドも一般ユーザ用コマンドと同じ場所にインストールされているため, システム管理用コマンドの設定を別途行う必要は無い).
    • 具体的には, 以下のようにする.
      • /etc/bash.bashrc の末尾に

        # add PATH for local installed softwares
        PATH="${PATH}:/usr/local/apache2/bin"
        # add PATH for local installed softwares (for root)
        if [ "`id -u`" -eq 0 ]; then
        PATH="${PATH}:/usr/local/apache2/bin"
        fi 
        export PATH

        を追加する.

      • /etc/csh.cshrc の末尾に

        # add PATH for local installed softwares
        set path = ($path /usr/local/bin /usr/bin /bin /usr/local/apache2/bin) 
        # add PATH for local installed softwares (for root)
        if ( "`id -u`" == 0 ) then
        set path = ($path /usr/local/sbin /usr/sbin /sbin /usr/local/apache2/bin)
        endif

        を追加する.

      • /etc/zsh/zshenv の末尾に

        # add PATH for local installed softwares
        export PATH="$PATH:/usr/local/apache2/bin"
        # add PATH for local installed softwares (for root)
        if [ "`id -u`" -eq 0 ]; then
          export PATH="$PATH:/usr/local/apache2/bin"
        fi
        # delete duplicated path setting
        typeset -U path 

        の記述を追加する.

マニュアルへのパスの設定

  • インストールされた Apache のマニュアル群へパスを通す.
    • /etc/manpath.config に以下の行を追加する. 詳しくは [ITPASS2020]パスの設定#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 で有効になっているモジュールを確認する.

    # /usr/local/apache2/bin/apachectl -t -D DUMP_MODULES
    • 結果, 以下の3つが最低限有効になっていないことを確認する.
      • ssl_module
      • rewrite_module
      • userdir_module
  • 有効になっていない場合, 以下のように対処する.
    • DSO(Dynamic Shared Object) を有効にしているので (configure 時に --enable-so をつけた), モジュールを追加する.
      • mod_ssl

        # cd /usr/local/src/httpd-2.4.51/modules/ssl
        # /usr/local/apache2/bin/apxs -c mod_ssl.c
        # /usr/local/apache2/bin/apxs -i -a -c -I /usr/include/openssl -I ../md -D HAVE_OPENSSL=1 -lcrypto -lssl *.c
      • mod_userdir

        # cd /usr/local/src/httpd-2.4.51/modules/mappers
        # /usr/local/apache2/bin/apxs -c mod_userdir.c
        # /usr/local/apache2/bin/apxs -i -a -n userdir mod_userdir.la
      • mod_rewrite

        # /usr/local/apache2/bin/apxs -i -a -n rewrite mod_rewrite.la
  • モジュールが正しく追加されたかを確認する.

    # /usr/local/apache2/bin/apachectl -t -D DUMP_MODULES

設定ファイルの編集

tako にある以下の設定ファイルのバックアップ (例えば http.conf なら, バックアップファイルは http.conf.bak とする) を取り, 同じ名前の設定ファイルを ika からコピーしてくる (ika から持ってきた設定ファイルを tako 内の以下のパスにコピーすると, 元あったファイルは上書きされるので, 必ず先にバックアップをとっておく). ika からコピーしたファイルの所有者・グループを確認し, root になっていなければ chown コマンドと chgrp コマンドを使い, 所有者・グループを root にしておく.

  • httpd 用
    • /usr/local/apache2/conf/httpd.conf
  • httpd-ssl
    • /usr/local/apache2/conf/extra/httpd-ssl.conf
  • バーチャルホスト設定用
    • /usr/local/apache2/conf/extra/httpd-vhosts.conf
  • 各ユーザの public_html 以下の設定用
    • /usr/local/apache2/conf/extra/httpd-userdir.conf

デフォルトから変更されている点は以下の通りである(以下は変更点の概要であり, 実際に行う作業はこのあとに記述).

  • httpd.conf
    • HTTP デーモンを起動するユーザを www-data にする
    • サーバ管理者 (ServerAdmin) のメールアドレスを設定
    • サーバ名 (ServerName) を設定
    • サーバのドキュメントルート (DocumentRoot) を /home/itpass/public_html に設定
    • ディレクトリのインデックスファイルに index.html 以外に index.htm index.htm.en index.html.en index.htm.ja index.html.ja も追加.
    • エラーログファイルを /var/log/httpd-error.log に設定
    • CGI に関する設定を変更
    • extra/httpd-vhosts.confをロード
    • extra/httpd-userdir.conf をロード
    • extra/httpd-ssl.conf をロード
    • /~gate, および /cgi-bin に対するアクセスを HTTPS へ移動させる.
    • hiki.cgi の置かれた場所で設定したすべての設定値の変更を, 下位のディレクトリで変更できるようにする.
    • hiki-IPtable, /home/yot/public_html/ で始まるディレクトリ, /home/shiraham/public_html/ で始まるディレクトリ以外では, mod_negotiation によるコンテントネゴシエーションされた "MultiViews" を許可する.
  • httpd-vhosts.conf
    • {epa,aoe}.scitec.kobe-u.ac.jp 宛の接続を受ける (virtual host)
      • ドキュメントルートは /home/{epalab,aoelab}/public_html にする
      • 管理者メールアドレスは itpadmin _at_ ... にする
      • http://{epa,aoe}.scitec.kobe-u.ac.jp/~gate/ 以下に対するアクセスを https://itpass.scitec.kobe-u.ac.jp/~gate に移動させる
    • http://itpass.scitec.kobe-u.ac.jp/{/hiki,/~epalab/hiki,/~itpass/hiki} に対するアクセスのみ HTTPS へ移動させる. その際, URI のエンコードは行わない.
  • httpd-userdir.conf
    • 所有者がマッチしなくてもシンボリックリンクの公開を許可する.
  • httpd-ssl.conf
    • ドキュメントルート (DocumentRoot), サーバ名 (ServerName), サーバ管理者アドレス (ServerAdmin), エラーログ (ErrorLog), アクセスログ (TransferLog) を設定する
    • epa.scitec, aoe.scitec の場合の https 接続を設定する

オリジナルとの diff

ika からコピーしてきたファイルとバックアップファイルの diff を取って確認する. httpd-ssl.conf の SSL 証明書 (Let's encrypt による証明書) の作成に関連する箇所については ika にあったファイルのままにしておく.

httpd.conf

chikuwa6@tako-itpass:/usr/local/apache2/conf$ sudo diff -u httpd.conf.bak httpd.conf
--- httpd.conf.bak      2022-10-25 16:19:14.985566726 +0900
+++ httpd.conf  2022-10-26 21:10:41.861477577 +0900
@@ -82,13 +82,12 @@
 #LoadModule auth_digest_module modules/mod_auth_digest.so
 #LoadModule allowmethods_module modules/mod_allowmethods.so
 #LoadModule file_cache_module modules/mod_file_cache.so
-#LoadModule cache_module modules/mod_cache.so
+LoadModule cache_module modules/mod_cache.so
 #LoadModule cache_disk_module modules/mod_cache_disk.so
 #LoadModule cache_socache_module modules/mod_cache_socache.so
 #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
 #LoadModule socache_dbm_module modules/mod_socache_dbm.so
 #LoadModule socache_memcache_module modules/mod_socache_memcache.so
-#LoadModule socache_redis_module modules/mod_socache_redis.so
 #LoadModule watchdog_module modules/mod_watchdog.so
 #LoadModule macro_module modules/mod_macro.so
 #LoadModule dbd_module modules/mod_dbd.so
@@ -141,16 +140,17 @@
 LoadModule status_module modules/mod_status.so
 LoadModule autoindex_module modules/mod_autoindex.so
 #LoadModule info_module modules/mod_info.so
-#LoadModule cgid_module modules/mod_cgid.so
+LoadModule cgid_module modules/mod_cgid.so
 #LoadModule dav_fs_module modules/mod_dav_fs.so
 #LoadModule vhost_alias_module modules/mod_vhost_alias.so
-#LoadModule negotiation_module modules/mod_negotiation.so
+LoadModule negotiation_module modules/mod_negotiation.so
 LoadModule dir_module modules/mod_dir.so
 #LoadModule actions_module modules/mod_actions.so
 #LoadModule speling_module modules/mod_speling.so
 LoadModule userdir_module     modules/mod_userdir.so
 LoadModule alias_module modules/mod_alias.so
 LoadModule rewrite_module     modules/mod_rewrite.so
+LoadModule cgid_module modules/mod_cgi.so 

 <IfModule unixd_module>
 #
@@ -159,10 +159,10 @@
 #
 # User/Group: The name (or #number) of the user/group to run httpd as.
 # It is usually good practice to create a dedicated user and group for
-# running httpd, as with most system services.
+# running httpdi a/mod_rewrite.so with most system services.
 #
-User daemon
-Group daemon
+User www-data
+Group www-data

 </IfModule>

@@ -183,7 +183,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 itpadmin@itpass.scitec.kobe-u.ac.jp  

 #
 # ServerName gives the name and port that the server uses to identifyitself.
@@ -192,7 +192,7 @@
 #
 # 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

 #
 # Deny access to the entirety of your server's filesystem. You must
@@ -216,8 +216,8 @@
 # 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"
-<Directory "/usr/local/apache2/htdocs">
+DocumentRoot "/home/itpass/public_html"
+<Directory "/home/itpass/public_html">
     #
     # Possible values for the Options directive are "None", "All",
     # or any combination of:
@@ -239,6 +239,8 @@
     #
     AllowOverride None 

+    Order deny,allow
+
     #
     # Controls who can get stuff from this server.
     #
@@ -250,7 +252,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>

 #
@@ -268,7 +270,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.
@@ -297,13 +299,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 "logs/access_log" combined
 </IfModule>

 <IfModule alias_module>
@@ -342,16 +344,16 @@
     # ScriptSock: On threaded servers, designate the path to the UNIX
     # socket used to communicate with the CGI daemon of mod_cgid.
     #
-    #Scriptsock cgisock
+    Scriptsock cgisock
 </IfModule>

 #
 # "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased
 # CGI directory exists, if you have that configured.
 #
-<Directory "/usr/local/apache2/cgi-bin">
-    AllowOverride None
-    Options None
+<Directory "/usr/local/apache2/cgi-bin/">
+    AllowOverride AuthConfig Limit
+    Options +ExecCGI +FollowSymLinks +IncludesNoExec
     Require all granted
 </Directory>

@@ -397,7 +399,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

     # For type maps (negotiated resources):
     #AddHandler type-map var
@@ -466,16 +468,16 @@
 #Include conf/extra/httpd-autoindex.conf

 # Language settings
-#Include conf/extra/httpd-languages.conf
+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
@@ -484,7 +486,7 @@
 #Include conf/extra/httpd-dav.conf

 # Various default settings
-#Include conf/extra/httpd-default.conf
+# Include conf/extra/httpd-none.conf

 # Configure mod_proxy_html to understand HTML4/XHTML1
 <IfModule proxy_html_module>
@@ -492,7 +494,7 @@
 </IfModule>

 # 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
@@ -502,4 +504,121 @@
 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/aoelab/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/itpass/public_html/hiki-secret">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/uwabami/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>
+
+<Directory "/home/itpass/public_html/hiki-IPtable">
+ AllowOverride ALL
+</Directory>
+
+<Directory "/home/yot/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes 
Options=ExecCGI,FollowSymlinks
+ ## apache 起動時のエラー発生原因 'Indexes Options=ExecCGI' を 
'IndexesOptions=ExecCGI' へ変更
+</Directory>
+<Directory "/home/yot/public_html/test_cgi">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/zzztmp">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/paramexp-cgi">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/dcpam_param_exp">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/dcpam_planets">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/dcpam_EarthSimplified">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/dcpam_EarthSimplified-02-test01">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/dcpam_EarthSimplified-03- summary">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/ebm">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/ebm_v2_N16AlbStep">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/insolation">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/time_conv">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/covid-19">
+    Options +ExecCGI
+</Directory>
+<Directory "/home/yot/public_html/cgis/seminar">
+    Options +ExecCGI
+</Directory>
+
+<Directory "/home/rin/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes 
Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/rin/public_html/hiki-pub">
+ AllowOverride FileInfo AuthConfig Limit Indexes 
Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+# uncomment out the below to deal with user agents that deliberately
+ # violate open standerds by misusing DNT (DNT *must* be a specific
+ # end-user choice)
+
+
+<Directory "/home/shiraham/public_html/testpage">
+Options +ExecCGI
+</Directory>
+
+<Directory "/home/shiraham/public_html/working">
+Options +ExecCGI
+EnableMMAP Off
+    EnableSendfile Off
+</Directory>
+
+<Directory "/home/chikuwa2/public_html/hiki">
+   AllowOverride ALL
+   Options -MultiViews
+</Directory>

extra/httpd-ssl.conf

chikuwa6@tako-itpass:/usr/local/apache2/conf/extra$ sudo diff -u httpd-ssl.conf.bak httpd-ssl.conf
--- httpd-ssl.conf.bak  2022-10-25 16:19:51.505770062 +0900
+++ httpd-ssl.conf      2022-10-26 21:11:19.717692147 +0900
@@ -49,8 +49,9 @@
 #   ensure these follow appropriate best practices for this deployment.
 #   httpd 2.2.30, 2.4.13 and later force-disable aNULL, eNULL and EXP ciphers,
 #   while OpenSSL disabled these by default in 0.9.8zf/1.0.0r/1.0.1m/1.0.2a.
-SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES
-SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES
+#SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES
+SSLCipherSuite
ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
+SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4

 #  By the end of 2016, only TLSv1.2 ciphers should remain in use.
 #  Older ciphers should be disallowed as soon as possible, while the
@@ -70,7 +71,7 @@
 #   must be the prerogative of the web server administrator who manages
 #   cpu load versus confidentiality, so enforce the server's cipher order.
 SSLHonorCipherOrder on
-
+SSLCompression off   # apache 起動時のエラー発生原因 'SSLCompressopn off' を 'SSLCompression off' へ変更
 #   SSL Protocol support:
 #   List the protocol versions which clients are allowed to connect with.
 #   Disable SSLv3 by default (cf. RFC 7525 3.1.1).  TLSv1 (1.0) should be
@@ -89,7 +90,7 @@
 #   Configure the SSL Session Cache: First the mechanism
 #   to use and second the expiring timeout (in seconds).
 #SSLSessionCache         "dbm:/usr/local/apache2/logs/ssl_scache"
-SSLSessionCache        
"shmcb:/usr/local/apache2/logs/ssl_scache(512000)"
+#SSLSessionCache        
"shmcb:/usr/local/apache2/logs/ssl_scache(512000)"
 SSLSessionCacheTimeout  300

 #   OCSP Stapling (requires OpenSSL 0.9.8h or later)
@@ -118,19 +119,19 @@
 ## SSL Virtual Host Context
 ##

-<VirtualHost _default_:443>
-
+#<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/itpass/public_html"
+ServerName itpass.scitec.kobe-u.ac.jp:443
+ServerAdmin itpadmin@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.
 SSLEngine on
-
+SSLProtocol all -SSLv2 -SSLv3
 #   Server Certificate:
 #   Point SSLCertificateFile at a PEM encoded certificate.  If
 #   the certificate is encrypted, then you will be prompted for a
@@ -141,9 +142,10 @@
 #   Some ECC cipher suites (http://www.ietf.org/rfc/rfc4492.txt)
 #   require an ECC certificate which can also be configured in
 #   parallel.
-SSLCertificateFile "/usr/local/apache2/conf/server.crt"
+SSLCertificateFile "/etc/letsencrypt/live/itpass.scitec.kobe-u.ac.jp/fullchain.pem"
 #SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"
 #SSLCertificateFile "/usr/local/apache2/conf/server-ecc.crt"
+#SSLCertificateFile "/usr/local/apache2/conf/ca/itpass/itpass.crt"

 #   Server Private Key:
 #   If the key is not combined with the certificate, use this
@@ -151,9 +153,10 @@
 #   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.)
 #   ECC keys, when in use, can also be configured in parallel
-SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
+SSLCertificateKeyFile "/etc/letsencrypt/live/itpass.scitec.kobe-u.ac.jp/privkey.pem"
 #SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"
 #SSLCertificateKeyFile "/usr/local/apache2/conf/server-ecc.key"
+#SSLCertificateKeyFile "/usr/local/apache2/conf/ca/itpass/itpass.key" 

 #   Server Certificate Chain:
 #   Point SSLCertificateChainFile at a file containing the
@@ -162,7 +165,7 @@
 #   the referenced file can be the same as SSLCertificateFile
 #   when the CA certificates are directly appended to the server
 #   certificate for convenience.
-#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
@@ -288,3 +291,39 @@
           "%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:442
+ServerAdmin itpadmin@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:!SSLv3:+EXP:+eNULL
+SSLCipherSuite
ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
+SSLCertificateFile "/etc/letsencrypt/live/aoe.scitec.kobe-u.ac.jp/fullchain.pem"
+SSLCertificateKeyFile "/etc/letsencrypt/live/aoe.scitec.kobe-u.ac.jp/privkey.pem"
+#SSLCertificateFile "/usr/local/apache2/conf/ca/aoe/aoe.crt"
+#SSLCertificateKeyFile "/usr/local/apache2/conf/ca/aoe/aoe.key"
+SSLProtocol all -SSLv2 -SSLv3
+SSLHonorCipherOrder On
+SSLCompression Off
+</VirtualHost>
+
+<VirtualHost *:443>
+DocumentRoot "/home/epalab/public_html"
+ServerName epa.scitec.kobe-u.ac.jp:443
+ServerAdmin itpadmin@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:!SSLv3:+EXP:+eNULL
+SSLCipherSuite
ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
+SSLCertificateFile "/etc/letsencrypt/live/epa.scitec.kobe-u.ac.jp/fullchain.pem"
+SSLCertificateKeyFile "/etc/letsencrypt/live/epa.scitec.kobe-u.ac.jp/privkey.pem"
+#SSLCertificateFile "/usr/local/apache2/conf/ca/epa/epa.crt"
+#SSLCertificateKeyFile "/usr/local/apache2/conf/ca/epa/epa.key"
+SSLProtocol all -SSLv2 -SSLv3
+SSLHonorCipherOrder On
+SSLCompression Off
+</VirtualHost>

extra/httpd-vhosts.conf

chikuwa6@tako-itpass:/usr/local/apache2/conf/extra$ sudo diff -u httpd-vhosts.conf.bak httpd-vhosts.conf
--- httpd-vhosts.conf.bak       2022-10-25 16:20:14.497898056 +0900
+++ httpd-vhosts.conf   2022-10-26 21:11:19.717692147 +0900
@@ -21,21 +21,71 @@
 # 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 itpadmin@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
+          LogLevel alert rewrite:trace1
+          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 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
-</VirtualHost> 

+ServerAdmin itpadmin@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
+          LogLevel alert rewrite:trace1
+          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@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
+      LogLevel alert rewrite:trace1
+      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

chikuwa6@tako-itpass:/usr/local/apache2/conf/extra$ sudo diff -u httpd-userdir.conf.bak httpd-userdir.conf
--- httpd-userdir.conf.bak      2022-10-25 16:20:37.518026153 +0900
+++ httpd-userdir.conf  2022-10-26 21:11:19.717692147 +0900
@@ -14,8 +14,15 @@
# for a site where these directories are restricted to read-only.
 #
 <Directory "/home/*/public_html">
-    AllowOverride FileInfo AuthConfig Limit Indexes
-    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+    AllowOverride FileInfo AuthConfig Limit Indexes Options
+    Options MultiViews Indexes FollowSymLinks IncludesNoExec
     Require method GET POST OPTIONS
+       <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 {
        delaycompress
        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 の設定を変更

/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 のそれぞれの名称で作成}

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

< 3 回実行する作業 ここから> 該当するディレクトリに移動する.

# cd itpass

秘密鍵を生成する.

# openssl genrsa -out itpass.key 2048

公開鍵を生成する(SHA-2(256)形式).

# openssl req -new -sha256 -key itpass.key -out itpass.csr

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, aoe のときはそれぞれ "EPA lab.", "AOE lab." として登録)
Common Name (eg, YOUR name) : itpass.scitec.kobe-u.ac.jp (ここは
itpass の他に, epa, aoe の分をそれぞれ作成)
Email Address: itpadmin_at_itpass.scitec.kobe-u.ac.jp (ここは同じ, "_at_" は "@" に修正)
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password: (空で Enter)
A optional company name: (空で Enter)

自己署名証明書を作成する.

# openssl x509 -req -in itpass.csr -signkey itpass.key -out itpass.crt

< 3 回実行した作業 ここまで>

ここまでを itpass, epa, aoe のそれぞれについて計 3 回行う.

apache への証明書の設定

/usr/local/apache2/conf/extra/httpd-ssl.conf を編集して発行した証明書を設定する.

# emacs /usr/local/apache2/conf/extra/httpd-ssl.conf

編集箇所は下の通り.

ServerName itpass.scitec.kobe-u.ac.jp:443 の項目内で下のように書き換える.

#SSLCertificateFile "/etc/letsencrypt/live/itpass.scitec.kobe-u.ac.jp/fullchain.pem"
SSLCertificateFile "/usr/local/apache2/conf/ca/itpass/itpass.crt"
#SSLCertificateKeyFile "/etc/letsencrypt/live/itpass.scitec.kobe-u.ac.jp/privkey.pem"
SSLCertificateKeyFile "/usr/local/apache2/conf/ca/itpass/itpass.key"

ServerName aoe.scitec.kobe-u.ac.jp:442 の項目内で下のように書き換える.

#SSLCertificateFile "/etc/letsencrypt/live/aoe.scitec.kobe-u.ac.jp/fullchain.pem"
#SSLCertificateKeyFile "/etc/letsencrypt/live/aoe.scitec.kobe-u.ac.jp/privkey.pem"
SSLCertificateFile "/usr/local/apache2/conf/ca/aoe/aoe.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/ca/aoe/aoe.key"

ServerName epa.scitec.kobe-u.ac.jp:443 の項目内で下のように書き換える.

#SSLCertificateFile "/etc/letsencrypt/live/epa.scitec.kobe-u.ac.jp/fullchain.pem"
#SSLCertificateKeyFile "/etc/letsencrypt/live/epa.scitec.kobe-u.ac.jp/privkey.pem"
SSLCertificateFile "/usr/local/apache2/conf/ca/epa/epa.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/ca/epa/epa.key"

動作チェック

  • apache を起動させる.

    # /usr/local/apache2/bin/apachectl -k start
    [Wed Oct 20 11:28:09.394269 2021] [so:warn] [pid 125397:tid 140011350308672] 
    AH01574: module cgid_module is already loaded, skipping
    AH00526: Syntax error on line 219 of /usr/local/apache2/conf/httpd.conf:
    DocumentRoot '/home/itpass/public_html' is not a directory, or is not readable
    • 上のようなエラーが出る場合は, /home 以下に itpass ディレクトリ,その下に public_html ディレクトリを作成する.

      # cd /home
      # mkdir itpass
      # cd itpass
      # mkdir public_html
    • 改めて apache を起動させる.

      # /usr/local/apache2/bin/apachectl -k start
      [Wed Oct 20 11:50:32.597550 2021] [so:warn] [pid 125535:tid 140452338857792] AH01574: module cgid_module is already loaded, skipping
      AH00112: Warning: DocumentRoot [/home/aoelab/public_html] does not exist
      AH00112: Warning: DocumentRoot [/home/epalab/public_html] does not exist
      AH00112: Warning: DocumentRoot [/home/aoelab/public_html] does not exist
      AH00112: Warning: DocumentRoot [/home/epalab/public_html] does not exist

 四つの warning は無視する.

  • 起動したかどうかを以下のコマンドで確認する.

    # ps aux | grep http
    • 画面左端に www-data と表示されれば, 起動できていることを確認できる.
  • /home/itpass/public_html/ に test.txt というファイルを作成する.
  • ブラウザで test.txt が正常に表示されるかどうかを確認する.
    • URL は http://tako-itpass.scitec.kobe-u.ac.jp/test.txt, https://tako-itpass.scitec.kobe-u.ac.jp/test.txt
      • "http://..." と "https://..." の両方に関して行う.
        • セキュリティに関する警告が出る場合があるが, それを無視して進むと正常に表示される.
  • apache を停止する.

    # /usr/local/apache2/bin/apachectl -k graceful-stop
    • 停止したかどうかを確認する.

      # ps aux | grep http
      • www-data の表示が消えたことを確認する.
    • apache のエラーログ /var/log/httpd-error.log を確認し, エラーなどが出ていないことを確認する.

起動スクリプトの用意

  • サーバの起動時に apache が起動させるための起動スクリプトを用意する.
    • Debian 8 から導入された systemd による起動設定を行う.

具体的には, <URL:http://www.smiyasaka.com/CentOS7.0_server21.html> を参考に, /etc/systemd/system に apache2.service を作成する.

#emacs apache2.service

以下を apache2.service に書き込む. この時, [Unit] の内容を適宜変更した.

[Unit]
Description=httpd-2.4.54 daemon

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl start

[Install]
WantedBy=multi-user.target
  • 起動テストを行い, 起動を確認する.

    # systemctl start apache2
    # ps aux | grep httpd
    • 画面左端に www-data と表示され, 起動できていることを確認できる.
  • システム起動時に apache が立ち上がるようにするために追加設定を行う.

    # systemctl enable apache2
  • tako を再起動して apache が起動するかを確認する.

    # reboot
    • 起動していることを確認する.

      # ps aux | grep httpd
Last modified:2023/06/12 09:32:32
Keyword(s):
References:[[ITPASS2022]2022年度サーバ構築マニュアル]