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

Apache のインストールと設定

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

ビルドのための設定

  • ソースを取得・展開する.

    ※ 2017 年 11 月 06 日時点の最新バージョンは 2.4.29 である.

    # cd /usr/local/src
    # wget 'http://ftp.tsukuba.wide.ad.jp/software/apache//httpd/httpd-2.4.29.tar.gz'
    # tar xvfz httpd-2.4.29.tar.gz
    # cd httpd-2.4.29
  • configure を行う.

    • インストール先と configure の際につけるオプションは以下の通りである.
      • インストール先
        • /usr/local/apache2 (apache2 のデフォルト)
          • configure の際に --prefix の設定は不要
    • 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" とエラーが生じる場合があるため)
      • apache2.4.x では apr と apr-util を別途用意する必要が有るため, <URL: http://apr.apache.org/download.cgi/> から最新版を取得し, 展開する. (参照: <URL: http://weblabo.oscasierra.net/install-apache24-1/>)
    $ wget http://ftp.jaist.ac.jp/pub/apache/apr/apr-1.6.3.tar.gz
    $ sudo mv apr-1.6.3.ta.gz /usr/local
    $ cd /usr/local
    $ sudo tar xzf apr-1.6.3.tar.gz
    
    $ cd apr-1.6.3
    $ sudo ./configure
    $ sudo make
    $ sudo make install
    
    $ cd
    $ wget http://ftp.jaist.ac.jp/pub/apache/apr/apr-util-1.6.1.tar.gz
    $ sudo mv apr-util-1.6.1.tar.gz /usr/local
    $ cd /usr/local
    $ sudo tar xzf apr-util-1.6.1.tar.gz 
    $ cd apr-util-1.6.1
    $ sudo ./configure --with-apr=/usr/local/apr
  • このままでは expat.h がないため make でエラーが出るので, 手動で expat.h を含むパッケージを取得する. Expat をソースからインストール : https://qiita.com/topology-lab/items/98caa12229fb5a6e8fc5

    $ wget https://github.com/libexpat/libexpat/releases/download/R_2_2_5/expat-2.2.5.tar.bz
    $ tar xvf expat-2.2.5.tar.bz2
    $ cd expat-2.2.5
    $ make
    $ make install
    $ cd ../src/httpd-2.4.29
    $ ./configure --prefix=/usr/local/expat
    $ sudo make
    $ sudo make install
    • PCRE をインストールする.
    $ sudo apt-get install libpcre3 libpcre3-dev
    • configure を行う.
    $ sudo ./configure --enable-ssl --enable-rewrite --enable-so --with-apr=/usr/local/apr
    • 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 のバイナリファイル群へパスを通す.
    • [ITPASS2017]パスの設定 <一般ユーザ用コマンドのパス> <システム管理用コマンドのパス> の両方に /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 に以下の行を追加する. 詳しくは [ITPASS2017]パスの設定#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_rewrite

        # /usr/local/apache2/bin/apxs -c mod_rewrite.c
        # /usr/local/apache2/bin/apxs -i -a -n rewrite mod_rewrite.la
      • mod_ssl

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

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

設定ファイルの編集

以下の設定ファイルを編集する. 編集はバックアップを取ってからコピーアンドペーストで行う(2016 年度追記).

  • 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 へ移動させる.
    • hiki.cgi の置かれた場所で設定したすべての設定値の変更を, 下位のディレクトリで変更できるようにする.
    • hiki-IPtable 以外では, 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.conf, 2016 年度追記).

httpd.conf

root@tako-itpass:/usr/local/apache2/conf# sudo diff -u original/httpd.conf   httpd.conf
--- original/httpd.conf 2017-11-06 16:10:31.924741417 +0900
+++ httpd.conf  2017-11-06 19:11:06.873306079 +0900
@@ -82,7 +82,7 @@
 #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
@@ -129,7 +129,7 @@
#LoadModule session_cookie_module modules/mod_session_cookie.so
#LoadModule session_dbd_module modules/mod_session_dbd.so
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
-#LoadModule ssl_module modules/mod_ssl.so
+LoadModule ssl_module modules/mod_ssl.so
#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
@@ -139,16 +139,16 @@
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 userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
-#LoadModule rewrite_module modules/mod_rewrite.so
+LoadModule rewrite_module modules/mod_rewrite.so

<IfModule unixd_module>
#
@@ -157,10 +157,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.
+# runningehttpdi a/mod_rewrite.so with most system services.
#
-User daemon
-Group daemon
+User www-data
+Group www-data

</IfModule>

@@ -181,7 +181,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 identify itself.
@@ -190,7 +190,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
@@ -214,8 +214,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:
@@ -237,6 +237,7 @@
    #
    AllowOverride None

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

#
@@ -266,7 +267,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.
@@ -295,13 +296,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>
@@ -340,16 +341,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>

@@ -395,7 +396,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
@@ -464,16 +465,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
@@ -482,7 +483,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>
@@ -490,7 +491,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
@@ -500,4 +501,73 @@
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/chikuwa2/public_html/hiki">
+ AllowOverride ALL
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/chikuwa3/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>
+
+<Directory "/home/yot/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI, FollowSymlinks    ## apache 起動時のエラー発生原因 'Indexes Options=ExecCGI' を 'IndexesOptions=ExecCGI' へ変更
+</Directory>
+
+<Directory "/home/okazakis/public_html/hiki">
+ AllowOverride FileInfo AuthConfig Limit Indexes Options=ExecCGI,FollowSymlinks
+ Options -MultiViews
+</Directory>
+
+<Directory "/home/shiojich/public_html/hiki">
+ 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)

extra/httpd-ssl.conf

root@tako-itpass:/usr/local/apache2/conf/extra# sudo diff -u ../original/extra/h
ttpd-ssl.conf httpd-ssl.conf
--- ../original/extra/httpd-ssl.conf    2017-11-06 16:10:31.988743325 +0900
+++ httpd-ssl.conf      2017-11-06 19:35:19.024717195 +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+3 DES: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,6 +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
+SSLCompressopn off   # apache 起動時のエラー発生原因 'SSLCompressopn off' を 'SSLCompression off' へ変更

#   SSL Protocol support:
#   List the protocol versions which clients are allowed to connect with.
@@ -89,7 +91,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 +120,20 @@
## 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/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,7 +144,7 @@
#   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 "/usr/local/apache2/conf/ca/itpass/itpass.crt"
#SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"
#SSLCertificateFile "/usr/local/apache2/conf/server-ecc.crt"

@@ -151,7 +154,7 @@
#   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 "/usr/local/apache2/conf/ca/itpass/itpass.key"
#SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"
#SSLCertificateKeyFile "/usr/local/apache2/conf/server-ecc.key"

@@ -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
@@ -287,4 +290,36 @@
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: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+3 DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
+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+3 DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
+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

root@tako-itpass:/usr/local/apache2/conf/extra# sudo diff -u ../original/extra/httpd-vhosts.conf httpd-vhosts.conf
--- ../original/extra/httpd-vhosts.conf 2017-11-06 16:10:32.004743801 +0900
+++ httpd-vhosts.conf   2017-11-06 19:59:00.303859738 +0900
@@ -21,21 +21,74 @@
# 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>


+erverAdmin itpadmin@itpass.scitec.kobe-u.ac.jp  # apache 起動時のエラー発生原因 'erverAdmin' を 'ServerAdmin' へ変更
+        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 
+      RewriteRule ^/cgi-bin/(.*)?$ https://itpass.scitec.kobe-u.ac.jp/cgi-bin/$1 [L,R,NE]
+    </IfModule>
+ </VirtualHost>

extra/httpd-userdir.conf

root@tako-itpass:/usr/local/apache2/conf/extra# sudo diff -u ../original/extra/httpd-userdir.conf httpd-userdir.conf
--- ../original/extra/httpd-userdir.conf        2017-11-06  16:10:31.996743563   +0900
+++ httpd-userdir.conf  2017-11-06 20:03:22.837291051 +0900
@@ -15,7 +15,14 @@
#
<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
-    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+    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 のコメントアウトを外す.

Let's encrypt による証明書の設定

以前はプライベート証明書を用いていたが, 現在は Let's encript (https://letsencrypt.org/) を利用した 証明書の設定を行う.

Let's Encrypt 総合ポータル (https://letsencrypt.jp/) の Let's Encrypt の使い方 (https://letsencrypt.jp/usage/) に従って作業する.

作業用ディレクトリの作成

作業ディレクトリを作成する.

$ sudo -s
# cd /usr/local/src
# mkdir certbot
# cd certbot

certbot のダウンロード

Let's Encrypt では, Debian 用に certbot のパッケージが用意 されている. しかし, このパッケージは apache2 の Debian パッ ケージに依存しているため, apache をソースから手動で make している itpass サーバでは使えない. そのため, https://certbot.eff.org/ から, 下のようにして certbot をダウンロードしてインストールする.

"Software" に apache を選択.
"System" に "Other UNIX" を選択.

当該ページの説明に従って, 下のように作業する.

# wget https://dl.eff.org/certbot-auto
# chmod a+x certbot-auto

証明書の発行

ダウンロードした certbot-auto を使って itpass.scitec.kobe-u.ac.jp 用の 証明書を発行する.

# ./certbot-auto --webroot certonly \
  --email itpadmin@itpass.scitec.kobe-u.ac.jp \
  --webroot-path /home/itpass/public_html \
  -d itpass.scitec.kobe-u.ac.jp

下のように聞かれるだろう.

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must

agree in order to register with the ACME server at

https://acme-v01.api.letsencrypt.org/directory

-------------------------------------------------------------------------------
(A)gree/(C)ancel:

A とする.

さらに下のように聞かれるだろう.

Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.

-------------------------------------------------------------------------------
(Y)es/(N)o:

N とする. (Y でも良いとは思うが.)

これで終了.

なお, certbot-auto のオプションの意味は下の通り.

  • --webroot 既に動作中のウェブサーバ上で, ウェブサーバを停止せずに証明書を発行する.
  • certonly apache の設定ファイルを自動で書き換えずに証明書を取得するのみ. 証明書は /etc/letsencrypt に置かれる.
  • --webroot-path RootPath の設定
  • --email 初回実行時にメールアドレスを尋ねられなくするためのオプション. つけなくて良かったような気がする.

同様に, epa.scitec.kobe-u.ac.jp, aoe.scitec.kobe-u.ac.jp 用の証明書を発行する.

# ./certbot-auto --webroot certonly \
  --email itpadmin@itpass.scitec.kobe-u.ac.jp \
  --webroot-path /home/epalab/public_html \
  -d epa.scitec.kobe-u.ac.jp
# ./certbot-auto --webroot certonly \
  --email itpadmin@itpass.scitec.kobe-u.ac.jp \
  --webroot-path /home/aoelab/public_html \
  -d aoe.scitec.kobe-u.ac.jp

apache への証明書の設定

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

# vi /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"
SSLCertificateKeyFile "/etc/letsencrypt/live/itpass.scitec.kobe-u.ac.jp/privkey.pem"

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"

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"

証明書更新のテスト

Let's encrypt の証明書の有効期限は 90 日である. このため, certbot-auto には簡単に証明書を更新する方法が存在する. その方法を設定する.

まずは下のようにして更新をテストする.

# ./certbot-auto renew --dry-run

これを定期的に実行するために cron のためのスクリプトを設定する. 下の内容の /etc/cron.local/daily/240_letsencrypt_renew を作成する.

#!/bin/sh
#
#= Renew certificate
#
MAINTAINERS="Yoshiyuki O. Takahashi"
UPDATE='2018-04-25'
VERSION='1.0'
REFERENCES='none'

COMMAND='/usr/local/src/certbot/certbot-auto'
DRYRUN='--dry-run'
DRYRUN=''

$COMMAND renew $DRYRUN

実行権限を与えること.

下のように動作テストを行い, 問題なく動作することを確認する. (ただし, この時点では証明書が新しいため更新されないだろう.)

# /etc/cron.local/daily/240_letsencrypt_renew

参考ページ

動作チェック

  • apache を起動する前に, ドキュメントルートとなるディレクトリを作成する.
    • /home/ 以下に itpass/, epalab/, aoe/ という名前のディレクトリを作る.
    • さらにそれぞれのディレクトリ内に public_html/ という名前のディレクトリを作る.
  • apache を起動
    • apache は /usr/local/apache2/bin/apachectl で起動/停止する

      # /usr/local/apache2/bin/apachectl -k start
    • 起動したかどうかを以下のコマンドで確認する.

      # ps aux | grep http

      画面左端に www-data と表示されている行があることを確認する.

  • ~itpass/public_html/ に test という名前のディレクトリを作成し, その中に test.txt というファイルを作成する.
  • ブラウザで test.txt が正常に表示されるかどうかを確認する.
    • URL は http://tako-itpass.scitec.kobe-u.ac.jp/test/test.txt, https://tako-itpass.scitec.kobe-u.ac.jp/test/test.txt
      • "http://..." と "https://..." の両方に関して行う.
  • apache を停止

    # /usr/local/apache2/bin/apachectl -k graceful-stop
    • 停止したかどうかを確認する.
    • apache のエラーログ /var/log/httpd-error.log を確認し, エラーなどが出ていないことを確認する.

起動スクリプトの用意

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

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

chikuwa2@tako-itpass /etc/systemd/system
% cat apache2.service
[Unit]
Description=httpd-2.4.17 daemon

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

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

    $ sudo systemctl start apache2
    $ ps aux | grep httpd
  • システム起動時に apache が立ち上がるようにするために追加設定を行う.

    $ sudo systemctl enable apache2
  • 再起動して apache が起動するかを確認する.
    • 起動していることを確認する.
Last modified:2018/04/26 20:12:22
Keyword(s):
References:[[ITPASS2017]2017年度サーバ構築マニュアル]