새로운 CentOS 7 설치(Google Compute), /etc/httpd/conf.d/에 VirtualHost 항목을 추가할 수 없습니다.

새로운 CentOS 7 설치(Google Compute), /etc/httpd/conf.d/에 VirtualHost 항목을 추가할 수 없습니다.

방금 기본 설치를 수행했는데 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
#

VirtualHost 정의와 충돌하는 Apache 2.4의 변경 사항이 있습니까?

내 구성을 거부하는 표준 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. 그래서 아파치가 해당 로그 파일을 쓸 수 있는 권한이 있는지 확인하기 위해 다음을 수행했습니다.

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

여전히 오류가 발생합니다. 조상 경로가 아파치에서도 실행 가능하다는 것을 확인했습니다.

/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

audit.log의 내용:

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가 다음을 수행하도록 허용할 수 있습니다.읽다적절한 부울, httpd_read_user_content. 아래 /srv/www또는 와 같이 보다 적절한 위치에 웹 콘텐츠를 재배치하는 것이 더 나은 생각일 것입니다 /var/www.

그러나 웹 서버가 다음을 수행하도록 허용하는 SELinux 부울은 없습니다.쓰다물론 본질적으로 위험합니다. 로그 파일을 다른 곳으로 옮겨야 합니다. 표준 위치는 입니다 /var/log/httpd. 사용자가 읽을 수 있어야 하는 경우 그렇게 할 수 있도록 권한을 설정할 수 있습니다.

관련 정보