본문 바로가기

리눅스

Apache 실행 오류 및 SELinux 관련 해결 방법

반응형

Apache 실행 오류 및 SELinux 관련 해결 방법

Apache 실행 오류

Apache를 재시작할 때 다음과 같은 경고 메시지가 출력됩니다.

[root@scbyun-ns1 named]$ service httpd restart
httpd 를 정지 중:                                          [  OK  ]
httpd (을)를 시작 중: Warning: DocumentRoot [/home/www/docs/www.scbyun.com] does not exist
                                                           [  OK  ]

/var/log/messages 로그에서는 아래와 같은 SELinux 관련 오류가 확인됩니다

[root@scbyun-ns1 named]$ tail -f /var/log/messages
Oct  9 14:02:19 scbyun-ns1 setroubleshoot: SELinux is preventing the httpd from using potentially mislabeled files (./docs). For complete SELinux messages. run sealert -l f5fd0e77-7b77-4ffe-ac24-b6788f775d44

원인

SELinux 정책으로 인해 Apache가 /home/www/docs 경로에 접근하지 못하는 문제가 발생했습니다. 해당 디렉터리에 대해 적절한 SELinux 컨텍스트가 설정되어 있지 않아 접근이 차단된 것입니다.

해결 방법

  • -R : 하위 디렉터리까지 재귀적으로 적용
  • -t httpd_user_content_t : Apache가 접근 가능한 파일 유형으로 설정
chcon -R -t httpd_user_content_t /home/www

적용 후 확인

Apache 재시작

service httpd restart

참고

보안상 필요하다면 restorecon 또는 semanage fcontext 명령어를 사용해 영구적으로 SELinux 컨텍스트를 설정할 수도 있습니다.

$ semanage fcontext -a -t httpd_user_content_t "/home/www(/.*)?"

$ restorecon -Rv /home/www
서비스 httpd 재시작
 
반응형