0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apacheのconfファイルがいつ反映されるか検証してみた

Last updated at Posted at 2022-08-09

はじめに

Apacheのコンフィグファイルを誤って変更した際に、リアルタイムにサーバーに反映されるか気になったため、検証してみました。
※Apacheのコンフィグファイルとは、/etc/httpd/conf配下または/etc/httpd/conf.d配下にある
confファイルです。

以下のサイトが参考になりました。
https://into-the-program.com/apache-httpdconf-check/

Apacheのコンフィグファイル変更前のwebページの状態

image.png

Apacheのコンフィグファイルを更新する

Apacheのコンフィグファイルを変更前に、バックアップを取得しました。

# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.confbk

Apacheのコンフィグファイルを開き、先頭にTESTという不要な文字を入れました。

# vi /etc/httpd/conf/httpd.conf

image.png

Apacheのコンフィグファイルを変更前と変更後で差分を比較しました。
変更後のコンフィグファイルに不要なTESTという文字が入っていることを確認した。

# sdiff -s  /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.confbk
TEST ServerRoot "/etc/httpd"                                  | ServerRoot "/etc/httpd"

文法チェックをしました

TEST文字列の部分にエラーが出ました。

# httpd -t
AH00526: Syntax error on line 31 of /etc/httpd/conf/httpd.conf:
Invalid command 'TEST', perhaps misspelled or defined by a module not included in the server configuration

Apacheのコンフィグファイル変更後のwebページの状態

シークレットウィンドウで確認したところ、問題なくwebページが表示されました。
image.png

試しにApacheのサービスを再起動してみました

エラーが出ました。

[root@localhost conf]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

シスログを確認しました。31行目にTESTの文字列によりエラーが出ていることを確認した

Aug  9 21:26:49 localhost systemd: Starting The Apache HTTP Server...
Aug  9 21:26:49 localhost httpd: AH00526: Syntax error on line 31 of /etc/httpd/conf/httpd.conf:
Aug  9 21:26:49 localhost httpd: Invalid command 'TEST', perhaps misspelled or defined by a module not included in the server configuration
Aug  9 21:26:49 localhost systemd: httpd.service: main process exited, code=exited, status=1/FAILURE
Aug  9 21:26:49 localhost systemd: Failed to start The Apache HTTP Server.
Aug  9 21:26:49 localhost systemd: Unit httpd.service entered failed state.
Aug  9 21:26:49 localhost systemd: httpd.service failed.
Aug  9 21:46:47 localhost systemd: Unit httpd.service cannot be reloaded because it is inactive.
Aug  9 21:47:03 localhost systemd: Starting The Apache HTTP Server...

Apacheサービス再起動後のwebページの状態

エラーページになりました。
image.png

まとめ

viエディタでApacheのコンフィグファイルを修正した際に、誤って変更した場合は、
Apacheのサービスを再起動しない限り、サーバーに反映されないことが分かりました。

また、Apacheのコンフィグファイルをバックアップから戻したり、
一時的に別名にApacheのコンフィグファイルを変更しても、Apacheのサービスを再起動しない限り、反映されないことも分かりました。

今後、viエディタでApacheのコンフィグファイルを、誤って修正することがあるかもしれません。
その場合、上記の知識があれば、落ち着いて対応出来ると思います。

補足ですが、よくあるミスが、viエディタで編集した際に入力モードにする「i」をコンフィグファイルに、気づかないうちに入れてしまう事があるため、こちらも作業する際は気を付けた方が良いと思いました。

この記事を参考にして頂けたら幸いです。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?