おりそ.doc

自分のしたことをアウトプットする場所

【備忘録】Apache2 デフォルトページを無効化したい

はじめに

/etc/httpd 形式じゃないことで躓いたので備忘録として残します。

環境

  • ViutualBox
  • Vagrant
  • Ubuntu22.04
  • Apache2.4

設定ファイルの置き場所は以下とします。

/etc/apache2

デフォルトページの無効化

結論から言うと「welcome.conf」は存在しない。

そのため、別の方法を模索する必要がある。

僕は、以下二点を実行することにした。

  • 「index.html」があるっぽいので削除する
  • 「apache2.conf」にデフォルトページに関する記述を変更/追加する

index.html の削除

そのまま削除してもいいけど別ファイルに名前を変えようと思う。

vagrant@vagrant:~$ ls -al /var/www/html/index.html
-rw-r--r-- 1 root root 10671 Sep 12 00:05 /var/www/html/index.html
vagrant@vagrant:~$ sudo mv /var/www/html/index.html /var/www/html/index.html.org
vagrant@vagrant:~$ ls -al /var/www/html/index.html
ls: cannot access '/var/www/html/index.html': No such file or directory
  • 変更前

  • 変更後

これはよろしくないのでconfファイルを変更する必要がある。

apache2.conf の変更

まずバックアップを取る。

vagrant@vagrant:~$ sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.o
rg
vagrant@vagrant:~$ sudo diff /etc/apache2/apache2.conf /etc/apache2/apache2.conf
.org
vagrant@vagrant:~$ sudo ls -al /etc/apache2/apache2.conf*
-rw-r--r-- 1 root root 7224 May  4 05:02 /etc/apache2/apache2.conf
-rw-r--r-- 1 root root 7224 Sep 15 06:22 /etc/apache2/apache2.conf.org

そして編集。

vagrant@vagrant:~$ sudo vim /etc/apache2/apache2.conf

Directory /var/www/

上記内の記述を変更する

変更前:Options Indexes FollowSymLinks

変更後:Options FollowSymLinks

vagrant@vagrant:~$ sudo diff /etc/apache2/apache2.conf /etc/apache2/apache2.conf.org
171c171
<       Options FollowSymLinks
---
>       Options Indexes FollowSymLinks

apache2 を再起動する。

vagrant@vagrant:~$ sudo systemctl restart apache2
vagrant@vagrant:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-09-15 06:36:20 JST; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 1922 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 1927 (apache2)
      Tasks: 6 (limit: 2233)
     Memory: 33.4M
        CPU: 161ms
     CGroup: /system.slice/apache2.service
             ├─1927 /usr/sbin/apache2 -k start
             ├─1928 /usr/sbin/apache2 -k start
             ├─1929 /usr/sbin/apache2 -k start
             ├─1930 /usr/sbin/apache2 -k start
             ├─1931 /usr/sbin/apache2 -k start
             └─1932 /usr/sbin/apache2 -k start

Sep 15 06:36:20 vagrant systemd[1]: Starting The Apache HTTP Server...
Sep 15 06:36:20 vagrant apachectl[1925]: AH00558: apache2: Could not reliably determine the>
Sep 15 06:36:20 vagrant systemd[1]: Started The Apache HTTP Server.
  • 変更後

これでデフォルトページが見れなくなった!

最後に

同じApache2.4 でも環境ごとに設定ファイルの置き場所やルールが違うことを改めて実感しました。

もっと意識していこうと思います。