0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

個人用備忘録:Apacheでハマったので、未来の自分へのメモとしてアウトプットしてみた

Posted at

はじめに

Apache HTTP Server(通称:Apache)は、最も広く使われているオープンソースのWebサーバーの一つです。

動的コンテンツから静的ファイルの配信、モジュールによる拡張性まで、幅広く対応できるのが特徴です。

ここでは、自分用の設定メモや使い方のポイントをまとめておきます。


書こうと思ったきっかけ

開発したWebアプリを社内サーバー上に簡単に公開するためにApacheを使う機会があり、設定のたびに毎回ドキュメントを探すのが手間だったため、基本的な構成や操作方法を備忘録として整理しました。

個人の備忘録程度の走り書きとなっておりますが、温かい目で見守っていただければ幸いです。


Apacheの基本機能

  • Webサーバーとして静的・動的コンテンツを配信
  • モジュールを使った柔軟な拡張(PHP, CGIなど)
  • バーチャルホストによる複数サイトの運用
  • アクセス制御、認証、HTTPS対応
  • ログ出力やリバースプロキシ機能もサポート

よく使うコマンド

# サーバーの起動・停止・再起動
sudo systemctl start httpd
sudo systemctl stop httpd
sudo systemctl restart httpd

# 設定ファイルの文法チェック
sudo apachectl configtest

# ログの確認
sudo tail -f /var/log/httpd/access_log
sudo tail -f /var/log/httpd/error_log

参考文献


基本的な構成ファイル

  • /etc/httpd/conf/httpd.conf:メイン設定ファイル
  • /etc/httpd/conf.d/:追加の設定ファイル格納場所
  • /var/www/html/:デフォルトのドキュメントルート

サンプル設定(静的ファイル配信)

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/example.com_error.log
    CustomLog /var/log/httpd/example.com_access.log combined
</VirtualHost>

参考文献


リバースプロキシ設定の例(mod_proxy使用)

<VirtualHost *:80>
    ServerName app.example.com

    ProxyPreserveHost On
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

    ErrorLog /var/log/httpd/app_error.log
    CustomLog /var/log/httpd/app_access.log combined
</VirtualHost>

参考文献


まとめ

Apacheは長年使われてきた信頼性の高いWebサーバーであり、柔軟な設定やモジュールによって多様な用途に対応できます。ローカルでの開発環境から本番公開まで、用途に応じた設定パターンを覚えておくことで、運用の効率が大きく向上します。

今後は、HTTPS対応(Let's Encrypt)、パフォーマンスチューニング、アクセスログ解析などにも取り組んでいきたいと考えています。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?