Apache: 설치와 가상 호스트
VPS에 Apache 설치하기, 가상 호스트와 모듈 구성하기, 포트 80에서 Nginx와의 일반적인 충돌 해결을 다뤄요.
업데이트 2026년 8월 23일
.htaccess가 필요하거나, 오래된 CMS를 쓰거나, 애플리케이션 개발자가 제공한 가이드가 준비되어 있을 때 Apache를 선택하세요. Nginx보다 메모리를 더 많이 쓰지만, 작은 사이트 하나를 운영하는 VDS-1에서는 체감하기 어려워요.
설치
apt update && apt install -y apache2 # Debian, Ubuntu
dnf install -y httpd && systemctl enable --now httpd # AlmaLinux, CentOS Stream
서비스 이름은 다릅니다. Debian과 Ubuntu에서는 apache2, RHEL 계열에서는 httpd예요. 설정 디렉터리도 다릅니다 — /etc/apache2와 /etc/httpd.
확인:
systemctl status apache2
curl -I http://127.0.0.1
가상 호스트
파일 /etc/apache2/sites-available/example.ru.conf:
<VirtualHost *:80>
ServerName example.ru
ServerAlias www.example.ru
DocumentRoot /var/www/example.ru
<Directory /var/www/example.ru>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.ru-error.log
CustomLog ${APACHE_LOG_DIR}/example.ru-access.log combined
</VirtualHost>
활성화 및 확인:
a2ensite example.ru
a2dissite 000-default
apachectl configtest && systemctl reload apache2
AllowOverride All은 실제로 .htaccess를 사용할 때만 필요해요. 사용하지 않는다면 None으로 설정하세요. 그러면 Apache가 매 요청마다 모든 디렉터리에서 이 파일을 찾지 않아요.
모듈
a2enmod rewrite headers ssl
systemctl restart apache2
활성화된 모듈 목록은 apache2ctl -M으로 확인해요. 전부 활성화하지 마세요. 모든 모듈은 각 워커 프로세스에 로드돼요.
PHP에는 구식 mod_php 대신 PHP-FPM을 사용하세요: PHP-FPM.
Apache와 Nginx 함께 사용하기
두 서버 모두 기본적으로 80번 포트에서 수신하므로, 두 번째 서버는 시작되지 않고 Address already in use 오류를 발생시켜요. 두 가지 방법이 있어요:
- 서버 하나만 유지하기;
- Nginx를 앞에 두고 Apache를
Listen 127.0.0.1:8080으로 전환한 뒤 프록시하기 — 리버스 프록시를 참고하세요.
포트를 사용 중인 프로세스 확인:
ss -tulpn | grep :80
자주 발생하는 오류
| 증상 | 원인 |
|---|---|
AH00558: Could not reliably determine ... server's fully qualified domain name | ServerName이 설정되지 않음 — 경고일 뿐이지만 설정해 두세요 |
.htaccess가 작동하지 않음 | Directory 블록의 AllowOverride None |
| 수정 후 서비스가 시작되지 않음 | 문법 오류 — 리로드 전에 항상 apachectl configtest를 실행하세요 |
| 디렉터리에서 403 | Require all granted 누락 또는 www-data에 권한 없음 |
로그: /var/log/apache2/ (Debian, Ubuntu) 또는 /var/log/httpd/ (AlmaLinux).
수정할 때마다 설정을 복사해 두세요:
cp file file.bak. 가상 머신에서는 한 시간 전에 무엇을 바꿨는지 기억하려 애쓰는 것보다 롤백하는 편이 더 쉬워요.