CentOS7 httpd 설정 파일 상세 분석

Apache HTTP 서버 설정을 이해하는 것은 웹 서비스 운영의 기본입니다. 이 문서에서는 CentOS7 환경의 주요 설정 파일들을 분석하여 각 지시어의 의미와 사용법을 상세히 설명합니다.

# /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd"                     # 서버 설정 파일의 기본 경로 지정
Listen 80                                    # 웹 서비스가 사용할 포트 번호
Include conf.modules.d/*.conf                # 모듈 관련 설정 파일을 포함
User apache                                  # 웹 서버 프로세스가 사용할 사용자/그룹
Group apache
ServerAdmin root@localhost                   # 오류 메시지 노출 시 사용될 관리자 이메일
DocumentRoot "/var/www/html"                 # 웹 문서가 저장된 기본 디렉터리 경로

<Directory />                               # 특정 디렉터리에 대한 접근 권한 설정
    AllowOverride none                      # .htaccess 파일의 지시어 사용 금지
    Require all denied                      # 모든 접근 차단 (보안 설정)
</Directory>

<Directory "/var/www">
    AllowOverride None
    Require all granted                     # /var/www 디렉터리에 대한 접근 허용
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks          # 디렉터리 목록 표시(비권장), 심볼릭 링크 추적 허용
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html               # 기본 시작 페이지 파일 지정
</IfModule>

<Files ".ht*">                              # .htaccess 등 숨김 파일에 대한 접근 제어
    Require all denied
</Files>

ErrorLog "logs/error_log"                   # 오류 로그 파일 경로 및 로그 레벨 설정
LogLevel warn

<IfModule log_config_module>               # 로그 포맷과 기록 방식 정의
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined     # 접근 로그를 combined 포맷으로 저장
</IfModule>

<IfModule alias_module>                     # CGI 스크립트 실행을 위한 별칭 경로 지정
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>                     # 파일 확장자와 MIME 타입 매핑 설정
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8                      # 기본 문자 인코딩 지정

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic                # MIME 타입 판별 파일 위치
</IfModule>

EnableSendfile on                            # sendfile 시스템 콜 사용으로 정적 파일 전송 성능 향상
# Linux 커널 2.1 이상에서만 사용 가능
# 파일 내용을 유저 공간으로 복사하지 않고 직접 소켓 버퍼로 전송
# 정적 파일 제공 속도를 크게 개선

IncludeOptional conf.d/*.conf                # 추가 설정 파일들을 선택적으로 포함
# /etc/httpd/conf.d/autoindex.conf

IndexOptions FancyIndexing HTMLTable VersionSort  # 디렉터리 목록 표시 옵션 (테이블 형식, 버전 정렬)
Alias /icons/ "/usr/share/httpd/icons/"            # 아이콘 파일을 제공할 별칭 경로
<Directory "/usr/share/httpd/icons">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride None
    Require all granted
</Directory>

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip  # 인코딩 방식에 따른 아이콘 할당
AddIconByType (TXT,/icons/text.gif) text/*                        # 파일 MIME 타입에 따른 아이콘 할당
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe                               # 파일 확장자에 따른 아이콘 할당
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif /core
AddIcon /icons/bomb.gif */core.*
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif                # 매핑되지 않은 파일 형식의 기본 아이콘
ReadmeName README.html                        # 디렉터리 목록 상단/하단에 표시할 파일
HeaderName HEADER.html
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t  # 디렉터리 목록에서 숨길 파일 패턴
# /etc/httpd/conf.d/welcome.conf

<LocationMatch "^/+$">                                   # 루트 URL("/")만 매칭
    Options -Indexes                                      # 디렉터리 목록 표시 기능 제거
    ErrorDocument 403 /.noindex.html                      # 403 오류 발생 시 대체 페이지 설정
</LocationMatch>

<Directory /usr/share/httpd/noindex>
    AllowOverride None
    Require all granted
</Directory>

Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
# /etc/httpd/conf.d/ssl.conf

Listen 443 https                                            # HTTPS 포트 활성화
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog  # 암호화된 개인키의 비밀번호 입력 방식
SSLSessionCache shmcb:/run/httpd/sslcache(512000)           # SSL 세션 캐시 저장 위치 및 크기
SSLSessionCacheTimeout 300                                  # SSL 세션 캐시 유효 시간 (초)
SSLRandomSeed startup file:/dev/urandom 256                 # 난수 생성기 시드 파일
SSLRandomSeed connect builtin                               # urandom 사용 불가 시 내장 난수 생성기 사용
SSLCryptoDevice builtin                                     # 하드웨어 암호화 장치 기본값 (builtin)
# SSLCryptoDevice rdrand                                    # Intel CPU의 하드웨어 난수 생성기 사용 예시

<VirtualHost _default_:443>
    ErrorLog logs/ssl_error_log
    TransferLog logs/ssl_access_log
    LogLevel warn

    SSLEngine on                                            # SSL/TLS 엔진 활성화
    SSLProtocol all -SSLv2                                  # 사용 가능 프로토콜 (SSLv2 제외)
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA     # 암호화 스위트 설정
    # HIGH: 3DES 기반 고강도 암호
    # MEDIUM: 128비트 암호
    # !: 제외할 암호 (aNULL: 인증 없음, MD5: 취약 해시, IDEA: 구식 암호)

    SSLCertificateFile /etc/pki/tls/certs/localhost.crt    # SSL 인증서 파일 경로
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key # SSL 개인키 파일 경로

    <Files ~ "\.(cgi|shtml|phtml|php3?)$">
        SSLOptions +StdEnvVars                              # CGI/SSI 실행 시 SSL 환경 변수 제공
        # 성능에 영향을 주므로 필요하지 않으면 비활성화 권장
    </Files>
    <Directory "/var/www/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-5]" \                             # 오래된 IE 브라우저 호환성 설정
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
    # User-Agent를 정규식으로 매칭하여 환경 변수 설정

    CustomLog logs/ssl_request_log \                       # SSL 요청 전용 로그
            "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

태그: Apache httpd CentOS7 SSL HTTPS

5월 22일 09:20에 게시됨