[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Low cost] Wasabi object storage construction and operation service

[Low cost] Wasabi object storage construction and operation service

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Global support for over 200 countries] eSIM Marketplace “beSIM”

[Global support for over 200 countries] eSIM Marketplace “beSIM”

[Suitable for local companies in China] China cloud / server construction, operation and maintenance

[Suitable for local companies in China] China cloud / server construction, operation and maintenance

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

【Apache】アクセスログの見方をやさしく解説!※2024年更新

こんにちは!
株式会社ビヨンド四国オフィスのペルシャ猫、いのうえです。

カッコよく言えば MSP の私が日々障害対応していくなかで、頻繁に見ることがあるアクセスログ。
今回は、MSP 必須!!Apacheのアクセスログの見方をやさしく解説していこうと思います。

※nginxのアクセスログの見方はコチラをチェック!

アクセスログってなんだ?

アクセスログとは、サーバーへ接続した履歴です。日付や時間、アクセス元のIPアドレスやリクエストされたページ、使用されたブラウザやデバイスなどの情報が記録されています。

私たちMSPがアクセスログを利用している一例として、アラート対応が挙げられます。

アラートが出ているサーバーのアクセスログを見て、平常時と比べてアクセス数が増減しているかを確認します。アクセス数が急増していればサーバーに大きな負荷がかかっていることになります。

またアクセスされているページを確認して、本当にがページ存在しているかを確認することもあります。

Apache のアクセスログを見てみよう!

[root@test-aws-harukainoue httpd]# tail access_log
xxx.xx.xx.xxx - - [11/Dec/2019:12:01:22 +0000] "GET / HTTP/1.0" 200 35 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3602.2 Safari/537.36"

※ 実行結果から一部抜粋しております。

なんだか、よくわからない英数字や記号がズラズラと並んでいます。

アクセスログを解析しよう!

Apache の設定ファイルは、デフォルトだと「/etc/httpd/conf/httpd.conf」に書かれています。
「/etc/httpd/conf/httpd.conf」ファイルの中を見ると

LogFormat "%h %l %u %t \"%r\" %t %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "logs/access_log" combined

と書かれており、combined というフォーマットがデフォルト設定されていることが分かります。
ログは、このフォーマットに添って表示される仕組みになっています。

フォーマット文字列 フォーマットの意味 アクセスログの値 備考
%h リモートホストのIPアドレス xxx.xx.xx.xxx
%l 接続元のユーザー名 ‐(未設定) ここは、だいたいの場合 - になっていることが多いですが
mod_ident がサーバに存在して、 IdentityCheck ディレクティブが On に設定されていると値が出力されます。
%u リモートユーザー ‐(未設定)
%t アクセスされた日時 2019/11/11 12:01
\"%r\" アクセスされたファイル ・アクション = GET

・HTTP = プロトコル

・リソース = 1.0

※バックスラッシュは、「\」で表示されています。
%>s ステータスコード 200(正常)
%b リソースに対する点送量 35バイト
\"%{Referer}i\" アクセス元のURL ‐(未設定) どこかのサイトを経由して来たのか、
URLから直接アクセスしたのかが出力されます。
\"%{User-Agent}i\" なんの OS でどのブラウザからアクセスしてきたか Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3602.2 Safari/537.36 ・OS = Linux

・ブラウザ = Chrome

ステータスコードの意味についてちょっと知ってみる

ステータスコードとは
 WebサーバーとWebブラウザが、お互いの状態をやり取りするために数字(コード)で表したもの
200 = リクエスト成功
301 = リクエストしたページが別のぺーじに移動している
302 = 一時的に別のページに移動中
403 = リクエストしたページを表示する権限なし
404 = リクエストしたページが存在しない
500 = サーバ側でエラー発生

まとめ

アクセスログを見ることができたら、MSP 力はグンと上がるはず!

日々、アラート対応していく中で、Webサーバーで急激に負荷が上がった際は、必ずアクセスログを見ます。
攻撃的なアクセスがあったかどうかも、アクセスログを確認するとわかります。
私も、目を血眼にしてアクセスログを見ています!(`・ω・´)
今回ブログに記したことで、私の理解度も深まりました。

今後もトライアンドエラーとやらを繰り返し、
お気に入りのコマンドや、個人的にもっと理解を深めたいことに関してブログを書いていきます。

また、今回はApacheのアクセスログの見方を解説しましたが、メンバーがnginxのアクセスログの見方についてもブログを書いてくれたので、こちらも併せてご覧ください!

【nginx】アクセスログの見方・設定・場所等を解説

日々成長、日々前進。
毎日、私自身をアップデートしていかなければ!!!
最後まで読んでくださって、ありがとうございます。

クラウド / サーバー運用監視サービス(24時間365日)はコチラ ▼ 

クラウド / サーバー運用監視サービス(24時間365日)

 

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
13
読み込み中...
13 票, 平均: 1.00 / 113
203,919
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Akika Inoue

Belongs to the System Solutions Department.
He joined Beyond as a founding member of the Shikoku office.
I jumped into the IT industry with no experience. As an education team, we create curriculum and conduct training for new graduates, mid-career, and existing members.
The main business is server operation and maintenance.
Either way, we value your content.
Also belongs to the Web Content Division and YouTube Team.