![新しい CentOS 7 のインストール (Google Compute)、/etc/httpd/conf.d/ に VirtualHost エントリを追加できません](https://rvso.com/image/697404/%E6%96%B0%E3%81%97%E3%81%84%20CentOS%207%20%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%20(Google%20Compute)%E3%80%81%2Fetc%2Fhttpd%2Fconf.d%2F%20%E3%81%AB%20VirtualHost%20%E3%82%A8%E3%83%B3%E3%83%88%E3%83%AA%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93.png)
ベース インストールを実行したところ、Apache 2.4 は問題なく起動しました。Apache 2.2 を実行している古いサーバーから移行しています。
/etc/httpd/conf.d
定義を含むファイルを に配置してVirtualHost
サーバーを再起動すると、起動時にクラッシュします。この VirtualHost 定義は、以前のサーバーから使用したものです。
# systemctl restart httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
# systemctl -l status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2017-01-22 03:03:35 UTC; 10s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 20621 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
Process: 20620 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 20620 (code=exited, status=1/FAILURE)
Jan 22 03:03:35 production-frontend-0 systemd[1]: Starting The Apache HTTP Server...
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jan 22 03:03:35 production-frontend-0 kill[20621]: kill: cannot find process ""
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service: control process exited, code=exited status=1
Jan 22 03:03:35 production-frontend-0 systemd[1]: Failed to start The Apache HTTP Server.
Jan 22 03:03:35 production-frontend-0 systemd[1]: Unit httpd.service entered failed state.
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service failed.
#
以下は conf ファイルの内容です (ドメイン名は変更されています)。
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory /home/kenny/domains/mydomain.com/html>
Options Indexes FollowSymLinks MultiViews ExecCGI Includes
AllowOverride All
</Directory>
DocumentRoot /home/kenny/domains/mydomain.com/html
CustomLog /home/kenny/domains/mydomain.com/logs/access.log combined
ErrorLog /home/kenny/domains/mydomain.com/logs/error.log
ScriptAlias /cgi-bin /home/kenny/domains/mydomain.com/cgi
RewriteEngine on
# Does the file exist?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ http://mydomain.otherdomain.com [R,L]
</VirtualHost>
ファイルの構文を確認しました:
# httpd -t
Syntax OK
#
ファイルを削除して再起動すると、Apache は正常に起動します。ファイルの権限が既存の conf ファイルと一致していることを確認しました。
# ls -l
total 20
-rw-r--r--. 1 root root 2926 Nov 14 18:04 autoindex.conf
-rw-r--r--. 1 root root 366 Nov 14 18:05 README
-rw-r--r--. 1 root root 1252 Nov 14 16:53 userdir.conf
-rw-r--r--. 1 root root 674 Jan 22 03:03 vhost.mydomain.com.conf
-rw-r--r--. 1 root root 824 Nov 14 16:53 welcome.conf
#
Apache 2.4 で何か変更があり、それが VirtualHost 定義と競合しているのでしょうか?
標準の Google Compute インスタンスに何らかのセキュリティ対策が施されていて、それが私の構成を拒否しているのでしょうか?
何年も前に古いサーバーで調整した構成オプションがあり、Google Compute インスタンスで調整する必要があることを忘れているだけでしょうか? :)
編集:
エラー ログに次の内容が見つかりました:
Permission denied: AH00649: could not open transfer log file /home/kenny/domains/mydomain.com/logs/access.log.
AH00015: Unable to open logs
確認したところhttpd.conf
、サーバーは User:Group として実行されているとのことでしたapache:apache
。そこで、Apache にこれらのログ ファイルを書き込む権限があることを確認するために、次の操作を実行しました。
chgrp -R apache /home/kenny/domains
chmod g+w /home/kenny/domains/mydomain.com/logs
まだエラーが発生します。以下も試しました:
touch /home/kenny/domains/mydomain.com/logs/access.log
chown kenny:apache /home/kenny/domains/mydomain.com/logs/access.log
chmod g+w /home/kenny/domains/mydomain.com/logs/access.log
まだエラーが発生します。祖先パスが Apache でも実行可能であることを確認しました。
/home/kenny is owned by kenny:kenny and is 755
/home/kenny/domains is owned by kenny:apache and is 755
/home/kenny/domains/mydomain.com is owned by kenny:apache and is 755
/home/kenny/domains/mydomain.com/logs is owned by kenny:apache and is 775
/home/kenny/domains/mydomain.com/logs/access.log is owned by kenny:apache and is 664
監査ログの内容:
type=AVC msg=audit(1485115416.525:2112): avc: denied { open } for pid=25759 comm="httpd" path="/home/kenny/domains/mydomain.com/logs/access.log" dev="sda1" ino=36516072 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file
type=SYSCALL msg=audit(1485115416.525:2112): arch=c000003e syscall=2 success=no exit=-13 a0=7f6620cd15a8 a1=80441 a2=1b6 a3=ffffff00 items=0 ppid=1 pid=25759 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=SERVICE_START msg=audit(1485115416.567:2113): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=httpd comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed
'
答え1
デフォルトで SELinux が有効になっている CentOS 7 を実行しています。
Apache を起動しようとすると、ユーザーのホーム ディレクトリにファイルを読み込もうとしますが、これはデフォルトでは許可されていません。
Apacheに許可を与えることができます読む適切なブール値 を設定することで、ユーザーのホーム ディレクトリ内のファイルを削除します。Web コンテンツを、またはhttpd_read_user_content
の下など、より適切な場所に再配置することをお勧めします。/srv/www
/var/www
しかし、Webサーバーに許可を与えるSELinuxブール値は存在しない。書くユーザーのホーム ディレクトリに保存されますが、これは当然のことながら、本質的に危険です。ログ ファイルは他の場所に移動する必要があります。標準的な場所は です/var/log/httpd
。ユーザーがログ ファイルを読み取る必要がある場合は、読み取り権限を設定できます。