apache 2.4.20の設定 その2

お絵かき 技術 Linux

前回の続き。とりあえず起動したけど、今後の方針的に一部機能を有効にするよう、設定変更する。尚、今後の方針とはこのサーバにリソース監視とか入れる予定です。※候補はmuninとxymonっす。


id=”目次”>目次

まずは前回も弄くった、httpd.confを修正します。

cd /usr/local/apache2/conf/
vi httpd.conf

で今回はこちらを修正します。

#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf
# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf
# Language settings
#Include conf/extra/httpd-languages.conf
# User home directories
#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
# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf
# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf
# Various default settings
Include conf/extra/httpd-default.conf
# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf

info,default.confを有効にします。sslとかvhostは別の機会にする。後で気がついたのだけど、server-info見たければ、該当module有効にしてあげないといかんです。httpd.confの以下を有効にしてあげて下さい。

LoadModule info_module modules/mod_info.so

httpd-info.conf

apacheの稼働状況とかの情報が見れます。ただ誰からでも見れるようにすると、セキュリティ的にあれなんで、制限をかけます。

#
# Get information about the requests being processed by the server
# and the configuration of the server.
#
# Required modules: mod_authz_core, mod_authz_host,
#                   mod_info (for the server-info handler),
#                   mod_status (for the server-status handler)
#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
<Location /server-status>
SetHandler server-status
Require ip 127.0.0.1 192.168.12.1 192.168.172.0/24
</Location>
#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
#ExtendedStatus On
#
# Allow remote server configuration reports, with the URL of
#  http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".example.com" to match your domain to enable.
#
<Location /server-info>
SetHandler server-info
Require ip 127.0.0.1 192.168.12.1 192.168.172.0/24
</Location>

スペース区切りで、IP個別やセグメントで許可出来ますよ。ここの書き方は2.4共通だよね?IP/server-info or IP/server-statusでブラウザから見れますよ。

httpd-default.conf

ここは今まで特に何も考えずに変更していたのですが、この度挙動の違いを確認しました。変更したのは以下二箇所

UseCanonicalName On
ServerTokens Prod

OffをOnに、FullをProdに変更しました。

UseCanonicalName

公式のドキュメントを引用。

多くの状況で Apache は自己参照 URL、すなわち 同じサーバを指す URL、を作成する必要があります。 UseCanonicalName On の場合は、ServerName ディレクティブで指定されている ホスト名とポート番号を使って、その正規名 (自己参照の名前) を生成します。 この名前は、すべての自己参照 URL で使われますし、CGI の SERVER_NAME と SERVER_PORT でも使われます。

OK、分かりやすく頼む。リダイレクトした時の挙動を決めているようだ。Onにしていると対象サーバのServerNameにリダイレクトする。

例えば、ServerName example.com:80でIPが172.22.22.22だとする。でDocumentRootにtestというディレクトリがある場合、http://172.22.22.22/test
でアクセスすると、http://172.22.22.22/test/にリダイレクトされる。
mod_dirの機能で末尾にスラッシュが保管されるのだが、ここで、UseCanonicalName をOnにしている場合、http://example.com:80/test/にリダイレクトされる。Offだとhttp://172.22.22.22/test/にリダイレクトされる事が分かった。
……とりあえず不要なのでOffに戻しておく。

UseCanonicalName Off
ServerTokens

レスポンスヘッダに返す情報が変わる。Fullの場合、

Server: Apache/2.4.20 (Unix) OpenSSL/1.0.1s

みたいな形でバージョンとかが外から丸わかりになる。Prodに変更すると。。

Server: Apache

無用な脆弱性を残さない為、ココはProdにしておいた方が良さそうだ。

これでapacheを再起動。設定が反映されたのを確認出来ました。今回いつにもまして手抜きですが、次回から何かしら突っ込んでいこうと思います。

【プロフィール】

【無音鈴鹿】
お絵かきが好きなエンジニアの成れの果て

Twitter


【広告】