LoginSignup
0
0

More than 1 year has passed since last update.

RockyLinux8 vps環境設定6) httpdの設定

Last updated at Posted at 2022-09-17

RockyLinux8 vps環境設定5) Swapの設定
https://qiita.com/naga_kt/items/a8649ea8da7303a7e6a6
の続き。WebArena Indigo(RockyLinux8.4)及びKagoya(RockyLinux8.5)での環境設定について述べる。

httpdのインストール

 インストールは以下のように行う。

$ sudo yum install httpd

 バージョンを確認すると以下のようになった。WebArena IndigoおよびKagoyaでインストールされたのはapache2.4だった。

$ httpd -v
Server version: Apache/2.4.37 (rocky)
Server built:   Mar 24 2022 17:33:25

起動と動作確認

 起動と動作確認は以下のコマンドで行う。

$ sudo systemctl start httpd
$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
   Active: active (running) since Mon 2022-05-09 11:51:32 JST; 12s ago
     Docs: man:httpd.service(8)
 Main PID: 260260 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 49273)
   Memory: 43.2M
   CGroup: /system.slice/httpd.service
           ┣260260 /usr/sbin/httpd -DFOREGROUND
           ┣260261 /usr/sbin/httpd -DFOREGROUND
           ┣260262 /usr/sbin/httpd -DFOREGROUND
           ┣260263 /usr/sbin/httpd -DFOREGROUND
           ┗260264 /usr/sbin/httpd -DFOREGROUND

May 09 11:51:32 i-zzzzzzzzzzzzzz systemd[1]: Starting The Apache HTTP Server...
May 09 11:51:32 i-zzzzzzzzzzzzzz httpd[260260]: AH00558: httpd: Could not relia>
May 09 11:51:32 i-zzzzzzzzzzzzzz systemd[1]: Started The Apache HTTP Server.
May 09 11:51:32 i-zzzzzzzzzzzzzz httpd[260260]: Server configured, listening on>

 動作確認して正常に動いているので、ブラウザに「http://IPアドレス」 を入力すればWebArena Indigoの場合はテストページが表示される。

ファイアウォールの設定【Kagoya(RockyLinux8.5)の場合】

 Kagoyaではファイアウォールの設定を変更する必要がある。
 以下のようにサービスとしてhttpを追加した

$ sudo firewall-cmd --permanent --add-service=http
success
$ sudo firewall-cmd –reload
success
$ sudo firewall-cmd --list-services --zone=public
cockpit dhcpv6-client http ssh

 この状態でブラウザに「http://IPアドレス」を入力すればKagoyaの場合でもテストページが表示される。

httpdのログ

 httpdのエラーログとアクセスログは以下の場所にある。表示がうまくできない時は参照して対処法を探す。

# cd /var/log/httpd/
# ls -lrt
total 24
-rw-r--r--. 1 root root  2743 May  9 16:29 access_log
-rw-r--r--. 1 root root 17375 May  9 16:29 error_log

/etc/httpd/conf/httpd.confの設定

 初期状態のままでサイトを表示させようとすると

Forbidden
You don't have permission to access this resource.

となった。エラーログを見ると以下のようになっていた。

[Mon May 09 16:41:53.150884 2022] [authz_core:error] [pid 280423:tid 140432470173440] [client xxx.xxx.xxx.xxx:yyyyy] AH01630: client denied by server configuration: ディレクトリパス

 この解決のためにhttpdの設定ファイルhttpd.confを書き変えた。
 バックアップを取っておいて書き換えする。

$ cd /etc/httpd/conf
$ ls -lrt
total 28
-rw-r--r--. 1 root root 11899 Mar 25 02:31 httpd.conf
-rw-r--r--. 1 root root 13064 Mar 25 02:34 magic
$ sudo cp -p httpd.conf httpd.conf-org
$ sudo vi httpd.conf

変更前

# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

変更後

<Directory />
    AllowOverride all
    Require all granted
</Directory>

 以下のようにして再起動する。

$ sudo service httpd restart
Redirecting to /bin/systemctl restart httpd.service

 Kagoyaの場合はここまででサイトが表示できた。

SELinuxの無効化【WebArena Indigo(RockyLinux8.4)の場合】

 WebArena Indigoの場合は、上記の設定変更でエラーログの出力が以下のように変わった。

[Mon May 09 16:53:27.996912 2022] [core:error] [pid 281228:tid 140422781318912] (13)Permission denied: [client xxx.xxx.xxx.xxx:yyyyy] AH00035: access to アドレス denied (filesystem path 'ディレクトリパス/index.html') because search permissions are missing on a component of the path

 これよりSELinuxによるアクセス制御が問題ではないかと判断できた。SELinuxの設定を以下のように確認するとONになっていることがわかった。

$ getenforce
Enforcing

 これを以下のようにOFFにしたところ、サイトが表示できるようになった。

$ sudo setenforce Permissive
$ getenforce
Permissive

 しかし、これだけでは再起動するとSELinux設定が元に戻るので、以下の永続化処理をする。/etc/selinux/configをコピーを取って編集する。

$ cd /etc/selinux/
$ ls -lrt
total 8
drwxr-xr-x. 2 root root    6 Apr 11  2018 tmp
-rw-r--r--. 1 root root 2321 Apr 11  2018 semanage.conf
-rw-r--r--. 1 root root  546 Oct  6  2018 config
drwxr-xr-x. 7 root root  215 Apr 12 16:17 targeted
drwx------. 2 root root    6 Apr 12 16:17 final
$ sudo cp -p config config-o
$ sudo vi config

 差分は以下である。

$ diff config config-o
7,8c7
< #SELINUX=enforcing
< SELINUX=permissive
---
> SELINUX=enforcing

設定ファイルが文法的に間違いないことを以下のようにして確認する。

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

 このようにSELinuxの設定はOFFにしたが、コントロールパネル上から何らかのセキュリティ制御は行なうつもりである。


RockyLinux8 vps環境設定7) コマンドのインストール
https://qiita.com/naga_kt/items/50c50e298946d5acf558
へ続く。


参考記事

Apache2.4で「AH01630: client denied by server configuration」解決方法
https://yongjinkim.com/apache2-4%E3%81%A7%E3%80%8Cah01630-client-denied-by-server-configuration%E3%80%8D%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95/

CentOS7.1 64bit SELinuxによるアクセス制御
https://www.kakiro-web.com/linux/selinux.html

【SELinuxの停止方法】なぜSELinuxを停止する必要があるのか【LPIC・LinuC303】
https://shanai-neet.com/?p=3964

【ざっくりと理解する】SELinuxとは?
https://eng-entrance.com/linux-selinux

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