안녕하세요 깍돌이 입니다 .아파치를 재시작하거나 시작 할때 해당 오류를 만나는 부분들이 꽤있는데요 

아주 단순한 케이스이지만 기록 해놓으려고 작성하게 되었습니다.

 

NCP(NaverCloudPlatform) & Init Script

NCP 클라우드 에서는 VM 을 생성시 Init Script 를 사용하여서 서버가 "운영중"으로 들어오기전에 하고싶은 작업들을 실행할수가 있습니다.  제가 하려고 했던 작업 중 일부분 입니다.

# 아파치 설치 
sudo -s yum -y install httpd
# 아파치 시작 
sudo -s systemctl start httpd
# 아파치 Root 디렉토리 변경
sudo -s sed -i 's/var\/www\/html/home1\/ncloud\/index.html/g' /etc/httpd/conf/httpd.conf
# 아파치 재시작  
sudo -s systemctl restart httpd

작성해놓았지만 동작이 되지않았기에 직접 VM에 들어가서 확인해보니

 

"Job for httpd.service failed because the control process exited with error code"

에러가 발생 중이였습니다. 뒤에 에러 코드에 보면 systemctl status httpd.service 를 보라는 문구가 있죠

 

Systemctl status httpd.service

원래 가장 친절한 에러 문구부터 파악을 해야겠죠

보시면 딱히 어떤 에러가 있는지는 확인이 쉽게 되지는 않게 나타나고 있습니다. 저희는 재시작 혹은 실행 에서 오류가 났기 때문에 해당 status에서 눈여겨 볼 점은 ExecStart 인데요

 

/usr/sbin/httpd 를 통해서 직접 실행을 해봅시다

 

ExecStart - /usr/sbin/httpd

결과 : '/home1/ncloud/index.html' is not a directory , or is not readable 

-> 제가 위에서 변경 하였던 오류였네요 루트 경로를 /var/www/html -> /home1/ncloud 로 했어야 하는데 index.html 까지 써버려서 폴더가 아니기 때문에 아파치의 welcome-list 필터링에서 오류가 발생하였습니다.

 

sudo -s sed -i 's/var\/www\/html/home1\/ncloud/g' /etc/httpd/conf/httpd.conf

 

/home1/ncloud로 변경 후 다시 시도시 (welcome-list에 의해서 index.html 을 찾을 겁니다)

 

정상적으로 나타났네요

 

* 별첨으로 Ubuntu와 Centos에서의 Apache (아파치) 설치 및 루트 디렉토리 변경이 조금씩 다르기 때문에

해당 관련 shell 을 첨부합니다.

 

Ubuntu 16.04-64 Server

#!/bin/bash

sudo -s apt-get update
sudo -s apt-get -y install apache2
# Create Apache New Index Folder
mkdir /home1/ncloud/www

# Change Apache Root Directory
sudo -s sed -i 's/var\/www\/html/home1\/ncloud\/www/g' /etc/apache2/sites-available/000-default.conf

# Change Apache Root Direceotry Access Authority
sudo -s sed -i 's/denied/granted/g' /etc/apache2/apache2.conf

# authority change 
sudo -s chmod -R 775 /home1
sudo -s chmod -R 775 /home1/ncloud
sudo -s chmod -R 775 /home1/ncloud/www
sudo -s chmod -R 775 /home1/ncloud/www/index.html

# Restart Apache
sudo -s /etc/init.d/apache2 restart

 

Centos 7.3-64

#!/bin/bash

# Apache Install
sudo -s yum -y install httpd
# Apache start
sudo -s systemctl start httpd

# Create Apache New Index Folder
mkdir /home1/ncloud/www

# Change Apache Root Directory
sudo -s sed -i 's/var\/www\/html/home1\/ncloud\/www/g' /etc/httpd/conf/httpd.conf

# authority change 
sudo -s chmod -R 775 /home1
sudo -s chmod -R 775 /home1/ncloud
sudo -s chmod -R 775 /home1/ncloud/www
sudo -s chmod -R 775 /home1/ncloud/www/index.html

# Restart Apache
sudo -s systemctl restart httpd

 

감사합니다.

꾸벅 @.@

+ Recent posts