./categories/os
Apache 설치·설정
1. 패키지 설치
yum install httpd httpd-devel
systemctl enable --now httpd
# nmap localhost → 80, 443
2. 소스 컴파일
yum install gcc* make pcre-devel expat-devel
Apache 2.2 — apr/apr-util 별도 설치
mkdir [httpd]/srclib/apr [httpd]/srclib/apr-util
cd apr-* && ./configure --prefix=[apr경로] && make && make install
# libtoolT 없으면: cp -arp libtool libtoolT
cd apr-util-* && ./configure --prefix=[apr-util경로] --with-apr=[apr경로] && make && make install
# expat.h 없으면: yum install expat-devel
Apache 2.4 — srclib에 포함
mv apr-* [httpd]/srclib/apr
mv apr-util-* [httpd]/srclib/apr-util
pcre · httpd
cd pcre-* && ./configure --prefix=/usr/local/pcre && make && make install
./configure --prefix=/usr/local/apache2 \
--with-pcre=/usr/local/pcre --with-included-apr \
--enable-so --enable-ssl --with-ssl=[openssl경로]
# apr 별도 설치 시: --with-apr=... --with-apr-util=...
make && make install
# 실패 시 make clean. 기존 옵션: httpd/build/config.nice
3. 서비스
# CentOS 7+: systemctl enable|start|stop|restart|status httpd
# CentOS 6: chkconfig --add httpd / service httpd start|stop|restart
apachectl start|stop|restart|graceful
# 또는 httpd -k start|stop|restart
apachectl configtest # 또는 httpd -t
4. 설정 요지
httpd.conf: ServerTokens prod, ServerSignature Off, ServerName, Timeout, User/Group, <Directory /> Require all granted
httpd-vhosts.conf 예:
Listen 80
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "/home/app/public_html"
DirectoryIndex index.php index.html
ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/error_%Y%m%d 86400"
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/access_%Y%m%d 86400" combined
# JkMount /* workername
# RewriteEngine on ��� HTTPS 리다이렉트
</VirtualHost>
Chrome ERR_UNSAFE_PORT 피하기: 1,7,9,21,22,25,53,80 외 well-known 등.
httpd-ssl.conf 요지: Listen 443, SSLEngine on, cert/key/CA, SSLProtocol/SSLCipherSuite. httpd -l에 mod_so, mod_ssl·openssl 패키지 확인.
5. Tomcat(mod_jk)
yum install autoconf libtool
cd tomcat-connectors/native
./configure --with-apxs=$(which apxs) && make && make install
workers.properties: worker.list와 워커명 일치(불일치 시 503).
httpd.conf: LoadModule jk_module + JkWorkersFile/JkLogFile/JkShmFile.
VHost: JkMount /* workername.
6. 비root 기동
80 바인딩은 root 권한 필요. 일반 계정 시:
# httpd.conf: User/Group = 일반계정
cd httpd/bin
chown root:testuser httpd && chmod +s httpd
chown testuser:testuser apachectl && ./apachectl start
7. 403 Forbidden
- SELinux:
disabled후 reboot, 또는chcon -R -h -t httpd_sys_content_t /path - Directory: 2.2
Order/Allow, 2.4Require all granted.Options Indexes는 목록 노출 주의. - 경로 상위 디렉터리 실행권한(755/711) 필요.
관련 링크: https://httpd.apache.org/docs/current/install.html
./comments