안녕세계

[Linux] Apache(CentOS) 설치 본문

[Linux] Apache(CentOS) 설치

Junhong Kim 2018. 4. 10. 18:27
728x90
반응형

Apache(CentOS) 설치

본 포스팅에서는 Apache(CentOS) 설치 및 Apache 웹 서버를 통해 HTML 문서를 웹 브라우저에 출력해봅니다.

개요

설치

$ yum install httpd

설치 위치

$ which httpd /usr/sbin/httpd

버전 확인

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

Apache(CentOS) 명령어

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

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

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의 내용이 출력됩니다. 

다음 포스팅은 아파치와 장고를 연결하는 과정을 살펴보겠습니다.

[참고]
https://zetawiki.com/wiki/아파치_웹서버
https://zetawiki.com/wiki/CentOS_아파치_설치
https://zetawiki.com/wiki/CentOS_6,_7_명령어_대응
http://blog.box.kr/?p=669
https://suwoni-codelab.com/linux/2017/05/27/Linux-CentOS-Apache/
http://www.happyjung.com/lecture/2232?sca=Linux

728x90
반응형

'Infra > Linux' 카테고리의 다른 글

[Linux] 쉘 스크립트로 간편하게 SSH 접속하기  (0) 2018.05.09
[Linux] Apache(CentOS)와 Django 연동  (0) 2018.04.10
[Linux] CentOS 명령어  (0) 2018.04.10
[Linux] CentOS 설치  (0) 2018.04.10
[Linux] hosts 파일  (0) 2018.04.02
Comments