Article sections

    설치

    $ yum install httpd
    
    None

    설치 위치

    $ which httpd
    /usr/sbin/httpd
    
    None

    버전 확인

    $ /usr/sbin/httpd -v
    $ httpd -v
    Server version: Apache/2.4.6 (CentOS)
    Server built:   Oct 19 2017 20:39:16
    
    None

    Apache(CentOS) 명령어

    Note:
    CentOS7(RHEL7)부터 기존에 사용하던 service 명령이 실행되지 않을 수 있습니다. systemctl 명령어를 사용해주세요.

    • systemctl: /usr/bin/systemctl
    • service: /sbin/service
    명령어 종류 systemctl (CentOS7) service (CentOS6)
    아파치 상태 확인 systemctl status httpd service httpd status
    아파치 시작 systemctl start httpd service httpd start
    아파치 정지 systemctl stop httpd service httpd stop
    아파치 재시작 systemctl restart httpd service httpd restart
    아파치 리로드 systemctl reload httpd service httpd reload
    아파치 자동시작 설정(On) systemctl enable httpd chkconfig httpd on
    아파치 자동시작 해제(Off) systemctl disable httpd chkconfig httpd off
    아파치 자동시작 확인 systemctl is-enabled httpd chkconfig httpd
    자동 실행 서비스 목록 systemctl list-unit-files –type=service chkconfig –list httpd
    아파치 마스크 systemctl mask http
    아파치 언마스크 systemctl unmask http
    방화벽 시작 systemctl start firewalld service iptables start
    방화벽 중지 systemctl stop firewalld service iptables stop
    방화벽 자동시작 적용 systemctl enable firewalld chkconfig iptables off
    방화벽 자동시작 해제 systemctl disable firewalld chkconfig iptables on

    Apache 실행 예제

    Apahce 주요 디렉토리

    • /etc/httpd
      • Apahce 디렉토리
    • /etc/httpd/conf
      • httpd.conf: Apache 설정 파일
      • magic: MIME 형식을 지정하기 위한 파일
    • /etc/httpd/conf.d
      • Apache 설정을 분리해서 저장하는 디렉토리
      • httpd.conf 설정 내용을 이 디렉토리에 저장하면 httpd.conf 파일이 현 디렉토리를 내용을 불러와서 사용
      • httpd.conf 파일 마지막에 IncludeOptional conf.d/*.conf 구문이 존재
    • /etc/httpd/log
      • 로그 파일이 저장되는 디렉토리
    • /etc/httpd/modules
      • Apache 모듈 설치 디렉토리

    1. 방화벽 설정

    $ firewall-cmd --permanent --add-service=http 
    $ firewall-cmd --permanent --add-service=https 
    $ firewall-cmd --reload
    
    None

    CentOS를 기본 설치할 경우 외부에서의 80 port 접근이 차단되어있습니다.
    ports: 80/tcp가 명시되어있는지 확인해주세요.

    [root@CentOS conf.d]# firewall-cmd --zone=public --list-all
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: eth0
      sources: 
      services: ssh dhcpv6-client http https
      ports: 80/tcp
      protocols: 
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 
    

    공란으로 되어있을 경우 80 port로 접근 가능하도록 정책을 추가하고 reload하세요.

    $ firewall-cmd –permanent –zone=public –add-port=80/tcp
    $ firewall-cmd --reload
    

    2. 아파치 자동시작 설정

    $ systemctl enable httpd

    3. 아파치 실행

    $ systemctl start httpd

    4. 웹 브라우저에 자신의 IP 입력후 접속

    http://[웹서버가 실행된 아이피 주소] 웹 브라우저에서 Testing 123..이 나오면 Apache 설치 및 구동이 완료된 것 입니다.

    5. 배포 디렉토리

    /etc/httpd/conf/httpd.conf 파일을 열면 Apache 설정 내용이있습니다.
    DocumentRoot "/var/www/html" 구문에 의해 /var/www/html 디렉토리의 파일을 웹 서버가 출력합니다.

    #
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    #
    DocumentRoot "/var/www/html"

    <IfModule dir_module/> 구문에 index.html이 기본 문서로 지정되어 있음을 확인 할수 있습니다.

    #
    # DirectoryIndex: sets the file that Apache will serve if a directory
    # is requested.
    #
    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>

    하지만, 현재 /var/www/html 디렉토리에는 파일이 존재하지 않습니다.
    /var/www/html 위치에 index.html 파일을 생성하고 다시 접속하면 index.html의 내용이 출력됩니다.

    in Server Doc