良く使うApache設定・操作まとめ20選

ステータス

ステータス確認

CentOS7・・・systemctl status httpd.service

起動

CentOS7・・・systemctl start httpd.service

自動起動

CentOS7・・・systemctl enable httpd

停止

CentOS7・・・systemctl stop httpd.service

再起動(強制的)

CentOS7・・・systemctl restart httpd.service

 再起動(切断しない)

  設定ファイル確認

conf設定 .htaccess設定

confファイルの場所

環境変数の指定

apache側で指定した変数をPHPなどのスクリプト言語で扱いたい場合

サイト引っ越し時の設定(301恒久的リダイレクト)旧サイト全ページ⇒新サイトTOP

サイト引っ越し時の設定(301恒久的リダイレクト)旧サイト全ページ⇒新サイト同階層ページ

httpからhttpsへの301恒久的リダイレクト

conf設定 mod_log_config

参考 https://httpd.apache.org/docs/2.2/ja/mod/mod_log_config.html#transferlog

LogFormatディレクティブ

ログの出力形式をテンプレートとして定義してテンプレートに名前をつける。テンプレートの定義だけでログは出力されない。

CustomLogディレクティブ

ログの出力形式と出力パスを定義してログを出力する。

LogFormatで定義したテンプレートを使用出来る。

conf設定 mod_proxy リバースプロキシ

http://test.com/ をサーバA

http://test.com/bbb/ をサーバBにしたい場合の設定手順です。

https://normalblog.net/system/apache-reverse-proxy-mod_proxy/

conf設定 mod_rewrite

サンプル)httpだったらhttpsにする

サンプル)httpだったらhttpsにするが、test.comの場合だけにする

ローカルではtest.localなどの場合で本番環境だけhttpsにしたい状況で、どちらでも対応出来る書き方をしたい場合。

ログ(LOG)ファイル

ログファイル格納場所

エラー

403 Forbidden[You don’t have permission to access / on this server.]

vagrant仮想環境にWordPressを構築しようとしています。 index.htmlを置いてブラウザからIPを叩いてみると以下の...

httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain for ServerName

wordpressを仮想環境で構築してみようとしています。 apacheのconfファイルを設定したところ、configtestで以下...

モジュール

インストール済モジュール確認