|
※※※ 注意事項 ※※※
下記の設定で使用している www.smiyasaka.com と smiyasaka.com は、私のドメイン名です。
コマンドをコピーする時には、あなたのドメインに変更して使用してください。
dnf でのインストールでは、httpd-2.4.37-XX のバージョンが標準仕様になっています。
httpd-2.4.37-XX の XX は、、2020年7月現在 21 に成っています。
1. httpd-2.4.37-XX と httpd-SSL のインストール
先ずは、SSL 無しで動作確認しますが、インストールは、httpd-2.4.37-XX と httpd-SSL を下記コマンドで行います。
dnf -y install mod_ssl httpd-devel
この結果、下記の15個のパッケージがインストールされます。
apr-1.6.3-9.el8.x86_64
apr-devel-1.6.3-9.el8.x86_64
apr-util-1.6.1-6.el8.x86_64
apr-util-bdb-1.6.1-6.el8.x86_64
apr-util-devel-1.6.1-6.el8.x86_64
apr-util-openssl-1.6.1-6.el8.x86_64
centos-logos-httpd-80.5-2.el8.noarch
httpd-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
httpd-devel-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch
httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
libdb-devel-5.3.28-37.el8.x86_64
mod_http2-1.11.3-3.module_el8.2.0+307+4d18d695.x86_64
mod_ssl-1:2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
openldap-devel-2.4.46-11.el8_1.x86_64
2. httpd の関連ディレクトリのパス
httpd の設定ファイル : /etc/httpd/conf
ssl.conf の設定ファイル : /etc/httpd/conf.d
httpd の実行ファイル : /usr/sbin
httpd のログファイル : /etc/httpd/logs
Web ページ用HTMLファイル : /var/www/html
Web で利用する CGI,SSI ファイル : /var/www/cgi-bin
3. LoadModule の有効・無効の設定
httpd-2.4.37-XX の httpd.conf には、LoadModule の行が有りませんが、LoadModule は、
59行目 Include conf.modules.d/*.conf の設定で、
/etc/httpd/conf.modules.d/00-base.conf とそ
の他の conf の設定ファイルを読込む設定になっています。
その他の conf ファイル名
00-dav.conf
00-lua.conf
00-mpm.conf
00-optional.conf
00-proxy.conf
00-ssl.conf
00-systemd.conf
01-cgi.conf
10-h2.conf
proxy_h2.conf
今回は各 conf の LoadModule の有効・無効の設定は、ここでは、特に何もしないで構築します。
------------------------------------------------------------------------------
4. openssl を openssl-1.1.1g にアップデートを行います。
カレントディレクトリ( ex. /usr/local/src )に下記4個の rpm パッケージを転送します。
openssl-1.1.1g-11.el8.x86_64.rpm
openssl-devel-1.1.1g-11.el8.x86_64.rpm
openssl-libs-1.1.1g-11.el8.x86_64.rpm
openssl-perl-1.1.1g-11.el8.x86_64.rpm
現在の openssl のバージョンをコマンド openssl version で確認しておきます。
OpenSSL 1.1.1c FIPS 28 May 2019 2020.10.30 現在 のバージョン
下記の様に dnf update コマンドで openssl をアップデートします。
cd /usr/local/src; \
dnf -y update openssl-1.1.1g-11.el8.x86_64.rpm \
openssl-devel-1.1.1g-11.el8.x86_64.rpm \
openssl-libs-1.1.1g-11.el8.x86_64.rpm \
openssl-perl-1.1.1g-11.el8.x86_64.rpm
実行結果は、下記の様になります。
アップグレード済み:
openssl-1:1.1.1g-11.el8.x86_64 openssl-devel-1:1.1.1g-11.el8.x86_64
openssl-libs-1:1.1.1g-11.el8.x86_64
完了しました!
アップデート後のバージョンを確認します。
OpenSSL 1.1.1g FIPS 21 Apr 2020
1.1.1g にアップデートされるはずです。
5. httpd.conf の編集
設定は、html, CGI, SSI を DocumentRoot とユーザホームディレクトリで動作させるようにしています。
原本は、保存しておきます。
cp /etc/httpd/conf/httpd.conf /home/miyasaka/httpd-2.4.37.conf.bak
vi /etc/httpd/conf/httpd.conf
69行目あたり
User apache
Group apache
↓ ↓
User ○○○○ ○○○○は、インストール時のユーザー名
Group ○○○○ ( 私は、CentOS 8.X の登録ユーザー名を使用しています。)
※※※ 注意 ※※※
(1) User・Group 名は、初期値 apache ですが、Alias を使うことから、CentOS 8.X の登録ユーザー名に変更します。
このままだと、SSI・CGI・Alias 等は、動作しませんので、User apache を User ○○○○のグループに下記コマンドで、apache を参加させます。
usermod -aG apache ○○○○
確認は、下記コマンドで行います。
id ○○○○
uid=1000(○○○○) gid=1000(○○○○) groups=1000(○○○○),10(wheel),48(apache)
(2) Alias によるユーザホームディレクトリの参照・プログラムの実行は、(1)を実行させないとできません。
89行目あたり
#ServerAdmin root@localhost ○○○○@○○○○は、あなたのメールアドレス
↓ ↓ ↓
ServerAdmin ○○○○@○○○○
98行目あたり
#ServerName www.example.com:80 ○○○○は、サーバ構築時に設定したホスト名
↓ ↓ ↓
ServerName ○○○○:80 ここは、設定しないとエラーになります。
105〜108行目あたり この位置では不要なのでコメントアウトします。
#<Directory />
# AllowOverride none
# Require all denied
#</Directory>
122行目あたり
DocumentRoot "/var/www/html/" ホームページプログラム保存先の指定
↓ ↓ ↓
DocumentRoot "/var/www/html/www.smiyasaka.com"
www.smiyasaka.com は、私のサーバ機の場合です。貴方の環境に合わせてください。
127〜131行目あたり この位置では不要なのでコメントアウトします。
#<Directory "/var/www"/>
# AllowOverride None
# Allow open access:
# Require all granted
#</Directory>
147行目あたり Indexesを削除してSSIとCGIを有効にする。
Includes : SSI の利用を許可する。
ExecCGI : CGI の利用を許可する。
-Indexes : インデックス表示を無効にする。
MultiViews : 多言語対応のホームページでない時には不要です。
Options Indexes FollowSymLinks
↓ ↓ ↓
Options Includes FollowSymLinks ExecCGI
Options -Indexes
154行目あたり htaccessの使用が出来る様に成ります。
AllowOverride None
↓ ↓ ↓
AllowOverride All
166行目あたり
インデックスファイルを設定 index.cgi を追加する
トップページが index.cgi でも実行する様にします。
DirectoryIndex index.html
↓ ↓ ↓
DirectoryIndex index.html index.cgi
173〜175行目あたり
ForceType text/html :
HTML文書の拡張子 .htm .html をMIMEタイプの拡張子 text/html として扱われます。
SetOutputFilter INCLUDES :
SSI処理のための mod_include モジュールで提供される
INCLUDES フィルタを 出力フィルタとして挿入、拡張子 .html で SSI を有効にします。
<Files ".ht*">
Require all denied
</Files>
↓ ↓ ↓
<Files *.html>
ForceType text/html
SetOutputFilter INCLUDES
</Files>
184行目あたり
ErrorLog "logs/error_log"
↓ ↓ ↓
#ErrorLog "logs/error_log"
219行目あたり
CustomLog "logs/access_log" combined
↓ ↓ ↓
#CustomLog "logs/access_log" combined
Include conf.d/httpd-log.conf <---- 別モジュールとし作成します。
234行目あたり
# Alias /webpath /full/filesystem/path
↓ ↓ ↓
Alias "/home" "/home/miyasaka/www" <---- 最後の / は、入れない
# .cgi .pl を有効にする。ここに書込まないと無効になる。
<Directory "/home/miyasaka/www">>
AllowOverride None
Options Includes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .pl
Require all granted <---- これを入れないと動かない
</Directory>
261行目あたり コメントアウト
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
↓ ↓ ↓
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
257〜261行目あたり コメントアウト
#<Directory "/var/www/cgi-bin">>
# AllowOverride None
# Options None
# Require all granted
#</Directory>
296行目あたり #を取り perl の拡張子 .pl を追加する
AddHandler cgi-script .cgi
↓ ↓ ↓
AddHandler cgi-script .cgi .pl
305〜306行目あたり
#を取り .htmlの追加 SSI の実行ファイルを .html をOKにします。
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
↓ ↓ ↓
AddType text/html .shtml .html
AddOutputFilter INCLUDES .shtml .html
318行目あたり
コメントアウト これを忘れると、ホームページの表示で文字化けが発生します。
( 一般的に、ホームページのヘッダー部分で文字コードを指定している為です。)
AddDefaultCharset UTF-8
↓ ↓ ↓
AddDefaultCharset Off
355行目あたり 先ずは、コメントアウトします。
IncludeOptional conf.d/*.conf
↓ ↓ ↓
#IncludeOptional conf.d/ssl.conf
以下は、最終行(356)に追加する。
圧縮処理は、zgip を使用します
Include conf.d/httpd-zgip.conf <---- 別モジュールとし作成します。
#--------------------------------------------------
# セキュリティ対策のため、最終行に追加しておきます。
# サーバ情報(バージョン)の非表示
ServerTokens Prod
# サーバ署名(バージョンとサーバ名)のOFF
ServerSignature Off
------------------------------------------------------------------------------
6. 別モジュールの作成
〇 httpd-log.conf の新規作成
空の httpd-log.conf ファイルを作成します。
touch /etc/httpd/conf.d/httpd-log.conf
vi コマンドで下記モジュール( log_config_module )の設定条件を書き込みます。
vi /etc/httpd/conf.d/httpd-log.conf
下記を貼り付け(コピペ)ます。
----------------------------------------------------------------------
<IfModule log_config_module>
#
#---------------------------------------------------------------------
# 不要なログの記録をさせない設定
#---------------------------------------------------------------------
#
# 拡張子による制限
SetEnvIf Request_URI\
".(gif)|(jpg)|(jpeg)|(png)|(bmp)|(ico)|(css)|(swf)$" no-logfile
#
#内部からのアクセスをログに記録しない対策
# IPアドレスによる制限 ローカル
SetEnvIf Remote_Addr "192.168.0." no-logfile
#
# サーチエンジンのログは取らない。
SetEnvIf User-Agent "Gigabot" no-logfile
SetEnvIf User-Agent "Googlebot" no-logfile
SetEnvIf User-Agent "MJ12bot" no-logfile
SetEnvIf User-Agent "msnbot" no-logfile
SetEnvIf User-Agent "psbot" no-logfile
SetEnvIf User-Agent "TurnitinBot" no-logfile
SetEnvIf User-Agent "Yahoo! Slurp" no-logfile
SetEnvIf User-Agent "Zealbot" no-logfile
#
# ワームによる制限のログは取らない。
SetEnvIf Request_URI "default\.ida" no-logfile
SetEnvIf Request_URI "null\.ida" no-logfile
SetEnvIf Request_URI "NULL\.IDA" no-logfile
SetEnvIf Request_URI "cmd\.exe" no-logfile
SetEnvIf Request_URI "root\.exe" no-logfile
SetEnvIf Request_URI "Admin\.dll" no-logfile
SetEnvIf Request_URI "^/_mem_bin/" no-logfile
SetEnvIf Request_URI "^/_vti_bin/" no-logfile
SetEnvIf Request_URI "^/c/" no-logfile
SetEnvIf Request_URI "^/d/" no-logfile
SetEnvIf Request_URI "^/msadc/" no-logfile
SetEnvIf Request_URI "^/scripts/" no-logfile
#
# CGIディレクトリ
SetEnvIf Request_URI "^/cgi-bin/" no-logfile
# 巡回ロボットがアクセスする robots.txt
SetEnvIf Request_URI "robots\.txt" no-logfile
#
# 長いURLへの対処
SetEnvIf Request_Method\
"(GET)|(POST)|(PUT)|(DELETE)|(HEAD)" logfile
SetEnvIf Request_Method "(OPTIONS)" no-logfile
#CustomLog logs/ssl_access_logs combined env=!no-logfile
#------------------------------------------------------------------
# Apacheのログローテートの 86400 540 の意味
# ローテートする周期を"秒"で指定します。
# 86400 ---> 24時間周期で行う指示 60秒 × 60分 × 24時間 = 86400秒
# 540 ---> Apacheの時間管理は、UTC なので
# 日本時間用のオフセット値 60分 × 9 = 540分
#
# ログファイルは、/var/log/httpd/ に
# smiyasaka_access_log_yyyymmdd( 年月日 )のファイル名で保存されます。
#------------------------------------------------------------------
CustomLog "|/usr/sbin/rotatelogs \
/var/log/httpd/smiyasaka_access_log_%Y%m%d 86400 540" combined env=!no-logfile
#
</IfModule>
----------------------------------------------------------------------
〇 アクセスログの確認
ログファイルの格納ディレクトリ /var/log/httpd/ は、属性変更しないと読めません。
下記コマンドで、属性変更します。
chmod 766 -R /var/log/httpd/
〇 httpd-zgip.conff の新規作成
空の httpd-zgip.conf ファイルを作成します。
touch /etc/httpd/conf.d/httpd-zgip.conf
vi コマンドで下記モジュールの設定条件を書き込みます。
vi /etc/httpd/conf.d/httpd-zgip.conf
下記を貼り付け(コピペ)ます。
----------------------------------------------------------------------
<IfModule mod_deflate.c>
#---------------------------------------------------------------
# 転送データの圧縮設定(画像以外全て圧縮する)
#実際の圧縮率は、1 も 3 も大差ありません
#---------------------------------------------------------------
# 圧縮レベル 1 に設定
DeflateCompressionLevel 1
#
# 全てを圧縮する設定
SetOutputFilter DEFLATE
#
# gzip圧縮に対応していない古いブラウザを除外
# Netscape 4.x has some problems...
# 送信先ブラウザがNetscape 4.xの場合はtext/htmlのみ圧縮
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
# 送信先ブラウザがNetscape 4.06-4.08の場合は圧縮しない
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# 送信先ブラウザがMSIEの場合は全て圧縮する
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#
# 画像以外全て圧縮する
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
#
# Make sure proxies don't deliver the wrong content
# プロキシサーバーが圧縮未対応ブラウザへ圧縮ファイルを送信しないようにする
Header append Vary User-Agent env=!dont-vary
# html や css, js, javescript などは個別指定
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/js
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/js
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
#
# 圧縮の確認用ログ設定
# 不要になったら、# で無効にしておく事。
# Deflateが有効になっているか確認するログの出力
#
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%) %{User-agent}i' deflate
CustomLog "logs/deflate_log" deflate
</IfModule>
7. sed コマンドによる一括編集
下記は、上記の各設定変更を sed コマンドで作成した httpd.conf の一括編集コマンドです。
編集時の行指定は、タイトル部を除いて一切していません。
------------------------------------------------------------------------------
cp /etc/httpd/conf/httpd.conf /home/miyasaka/httpd-2.4.37.conf.bak
sed -i -e "1s/^#/# *** CentOS8\.X httpd-2\.4\.37 Edited httpd\.conf ***/
s/User apache/User miyasaka/
s/Group apache/Group miyasaka/
#
s/ServerAdmin root@localhost/ServerAdmin sample@hotmail\.co\.jp/
s/#ServerName www\.example\.com:80/ServerName sample:80/
#
/# <Directory> blocks below/,/# below/s/<Directory \/>/#<Directory \/>/
/# <Directory> blocks below/,/# below/s/\ AllowOverride/# AllowOverride/
/# <Directory> blocks below/,/# below/s/\ Require/# Require/g
/# <Directory> blocks below/,/# below/s/<\/Directory/#<\/Directory>/
#
#------------------------------------------------------------------
# DocumentRoot の設定 ( ここは、コメントです。)
#------------------------------------------------------------------
s/DocumentRoot \"\/var\/www\/html\"/DocumentRoot \"\/var\/www\/html\/www.smiyasaka.com\"/g
#
/<Directory \"\/var\/www\">/,/# Further relax access/s/^/#/
#------------------------------------------------------------------
# SSI, CGI の設定 ( ここは、コメントです。)
#------------------------------------------------------------------
#
s/Options Indexes FollowSymLinks/Options Includes FollowSymLinks ExecCGI\n\
Options -Indexes/
s/AllowOverride None/AllowOverride All/
#
/DirectoryIndex index\.html/s/$/ index\.cgi/
#
s/<Files \"\.ht\*\">/<Files \*\.html>/
/<Files \*\.html>/,/<\/Files>\/html/s/Require all denied/ForceType text\/html\n\
\ SetOutputFilter INCLUDES/g
#
/ErrorLog \"logs\/error_log\"/s/^/#/
/CustomLog \"logs\/access_log\"/s/^/#/
/CustomLog \"logs\/access_log\" combined/a\
#---------------------------------------------------------------------\n\
# 不要なログの記録をさせない設定\n\
#---------------------------------------------------------------------\n\
Include conf\.d\/httpd-log\.conf\n\
#\n\
#
#------------------------------------------------------------------
# Alias が不要な場合は、削除して下さい。( ここは、コメントです。)
#------------------------------------------------------------------
s/# Alias \/webpath \/full\/filesystem\/path/Alias \"\/home\" \"\/home\/miyasaka\/www\"\n\
# \.cgi \.pl を有効にする。ここに書込まないと無効になる。\n\
<Directory \"\/home\/miyasaka\/www\">\n\
AllowOverride None\n\
Options Includes FollowSymLinks ExecCGI\n\
AddHandler cgi-script \.cgi \.pl\n\
Require all granted\n\
<\/Directory>/
#-------------------------------------------------------------------
/ScriptAlias \/cgi-bin/s/^/#/
#
#
/<Directory \"\/var\/www\/cgi-bin\">/,/<\/Directory>/s/^/#/
#
s/#AddHandler cgi-script \.cgi/AddHandler cgi-script \.cgi \.pl/g
#
/\.shtml/s/$/ \.html/
#
# AddDefaultCharset UTF-8 --> Off
s/UTF-8/Off/
#
# SSL を使用する時
#/IncludeOptional/s/*\.conf/ssl\.conf/
#
# SSL を使用しない時
/IncludeOptional/s/^/#/
#
\$a#---------------------------------------------------------------------\n\
# 圧縮処理( zgip )の設定\n\
#---------------------------------------------------------------------\n\
#\n\
Include conf\.d\/httpd-zgip\.conf\n\
#\n\
#---------------------------------------------------\n\
# セキュリティ対策のため、最終行に追加しておきます。\n\
# サーバ情報\(バージョン\)の非表示\n\
ServerTokens Prod\n\
# サーバ署名\(バージョンとサーバ名\)のOFF\n\
ServerSignature Off" /etc/httpd/conf/httpd.conf
------------------------------------------------------------------- |
|