[Linux] Apache 서버 설치와 설정 가이드

Apache HTTP Server는 전 세계적으로 가장 널리 사용되는 오픈소스 웹 서버 중 하나로, 다양한 운영체제에서 폭넓게 활용됩니다.
Apache를 리눅스 서버에 설치하고, 기본 설정하는 방법 정리했습니다.

 

 

1. Apache 설치하기

✔ Ubuntu/Debian 계열

sudo apt update
sudo apt install apache2

✔ RHEL/CentOS 계열

sudo dnf install httpd

 

 

2. Apache 서비스 관리

설치 후 Apache 데몬을 시작하고, 상태를 확인할 수 있습니다.

✔ 서비스 시작/중지/재시작

sudo systemctl start apache2     # Ubuntu
sudo systemctl start httpd       # CentOS/RHEL

sudo systemctl stop apache2
sudo systemctl restart apache2

✔ 서비스 상태 확인

sudo systemctl status apache2    # Ubuntu
sudo systemctl status httpd      # CentOS/RHEL

✔ 부팅 시 자동 시작 설정

sudo systemctl enable apache2
sudo systemctl enable httpd

 

 

3. 방화벽에 HTTP/HTTPS 포트 열기

Apache는 HTTP(80)과 HTTPS(443) 포트를 사용하므로, 방화벽 설정이 필요합니다.

✔ UFW (Ubuntu)

sudo ufw allow 'Apache Full'

✔ firewalld (CentOS/RHEL)

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

 

 

4. 기본 웹 페이지 확인

서버의 IP로 브라우저에 접속하면 기본 Apache 테스트 페이지를 볼 수 있습니다.

http://서버_IP

이 페이지가 뜨면 Apache가 정상적으로 설치되어 실행 중이라는 의미입니다.

 

 

5. Apache 기본 설정 파일 위치

Apache 설정은 배포판에 따라 경로가 다소 다릅니다:

  • Ubuntu/Debian
    • /etc/apache2/apache2.conf – 메인 설정 파일
    • /etc/apache2/sites-available/ – 가상 호스트 설정 디렉토리
    • /etc/apache2/sites-enabled/ – 활성화된 사이트 심볼릭 링크
  • CentOS/RHEL
    • /etc/httpd/conf/httpd.conf – 메인 설정 파일
    • /etc/httpd/conf.d/ – 추가 설정 파일 디렉토리

 

 

6. 가상 호스트(Virtual Host) 설정 예제

가상 호스트를 사용하면 하나의 서버로 여러 도메인을 서비스할 수 있습니다.

✔ Ubuntu/Debian 예제 (sites-available/example.conf)

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com

    <Directory /var/www/example.com>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example_error.log
    CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>

심볼릭 링크로 활성화한 후 Apache를 재시작합니다:

sudo a2ensite example.conf
sudo systemctl reload apache2

 

 

7. 설정 테스트 및 적용

문법 오류를 확인합니다:

sudo apachectl configtest

정상 메시지(Syntax OK)가 출력되면 Apache를 재시작합니다:

sudo systemctl restart apache2

 

 

Apache로 웹 서버 구축하기

Apache는 안정성과 확장성이 뛰어난 웹 서버로, 리눅스에서 쉽게 설치할 수 있습니다.