Aapche とは?
世界的に使用されるWeb サーバーソフトの1つです。
Windows、Mac、Linux などの主要な OS で動作し、オープンソースのため無料での使用が可能です。
Apache は、同時処理数が多いほど、メモリを大量に消費し動作が重くなりがちです。そのため、多人数が同時に使用するようなWebサイトには不向きといえます。
Aapche のインストール
sudo dnf install -y httpd
確認コマンド
バージョンの確認
httpd -V
# バージョン情報のみ表示
httpd -v
Apache 読み込まれているモジュールの一覧の表示
httpd -M
# less での表示。終了するときは、「 q 」を入力。
httpd -M | less
Apacheのファイル構成
AlamLinux9 の Apache のファイル構成は以下のようになっていました。
LANG=C tree /etc/httpd
/etc/httpd
│-- conf
│ │- httpd.conf
│ └-- magic
│-- conf.d
│ │-- README
│ │-- autoindex.conf
│ │-- userdir.conf
│ └-- welcome.conf
│-- conf.modules.d
│ │-- 00-base.conf
│ │-- 00-brotli.conf
│ │-- 00-dav.conf
│ │-- 00-lua.conf
│ │-- 00-mpm.conf
│ │-- 00-optional.conf
│ │-- 00-proxy.conf
│ │-- 00-systemd.conf
│ │-- 01-cgi.conf
│ │-- 10-h2.conf
│ │-- 10-proxy_h2.conf
│ └-- README
│-- logs ->../../var/log/httpd
│-- modules -> ../../usr/lib64/httpd/modules
│-- run -> /run/httpd
└-- state -> ../../var/lib/httpd
設定ファイルのパス
メインの設定ファイル | /etc/httpd/conf/httpd.conf |
---|---|
補助設定ファイル | /etc/httpd/conf.d |
設定ファイルのパス
# メインの設定ファイル
/etc/httpd/conf/httpd.conf
# 補助設定ファイル
/etc/httpd/conf.d
systemctl での操作
# 起動
sudo systemctl start httpd
# httpd の再起動
sudo systemctl restart httpd
# httpd の状態の確認
sudo systemctl status httpd
# 自動起動の有効化
sudo systemctl enable httpd
シンタックスエラーの確認
sudo httpd -t
apachectl configtest
ファイヤーウォールのポートの解放設定
sudo firewall-cmd --add-service=http --zone=public --permanent
sudo firewall-cmd --add-service=https --zone=public --permanent
sudo firewall-cmd --reload
ログ
# エラーログ
sudo less /var/log/httpd/error_log
# アクセスログ
sudo less /var/log/httpd/access_log
リバースプロキシの設定
「 /etc/httpd/conf.d/ 」に「 exproxy.conf 」というファイルを作成してプロキシサーバーの設定をします。
<VirtualHost *:80>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
テストページの非表示
Apacheの設定ファイルを開きLocationの括りをすべてコメントアウトします。
sudo vi /etc/httpd/conf.d/welcome.conf
#
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
#LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /poweredby.png /usr/share/httpd/icons/apache_pb3.png
Alias /system_noindex_logo.png /usr/share/httpd/icons/system_noindex_logo.png
上記の変更だけだとIndex ofが表示されたままになるため、/etc/httpd/conf/httpd.confも変更します。
sudo vi /etc/httpd/conf/httpd.conf
以下のようにOptions Indexes FollowSymLinksをOptions -Indexesに変更します。
# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
Options -Indexes