Linux

[Linux] Apache

TTOII 2022. 3. 11. 12:35
728x90

✔️ Apache란 ?

https://tomcat.apache.org/download-90.cgi
  • Apache 재단에서 만든 HTTP 서버이며 세계에서 가장 많이 쓰이는 웹 서버 중 하나이다.
  • 다양한 플랫폼에서 동작할 수 있도록 강력하고 유연한 설계
  • 동적 공유객체 지원
  • 모든 사용으로 기능 추가가 용이

✔️ Apache 설정

패키지 설치

yum -y install httpd

서비스 시작 및 활성화

systemctl start httpd
systemctl enable httpd

방화벽 설정

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

✔️ Apache 구성

/etc/httpd/conf/httpd.conf

  • 키/값 구성 지시문과 HTML 유사 블록 2부분으로 구성
  • 블록 외부의 키/값 구성은 전체 서버 구성에 영향
  • 블록 내부의 지시문은 지정된 구성이나 설정한 요구 조건이 충족될 때만 적용
ServerRoot "/etc/httpd" # 구성 파일이 참조하는 위치의 기준점

Listetn 80 # httpd에 모든 인터페이스의 포트 80/TCP에서 수신 대기(중복 사용 금지)

Include conf.modules.d/*.conf # 모듈을 로드할 구성파일

User apache # httpd 데몬이 시작되면 실행되는사용자 및 그룹 지정
Group apache

ServerAdmin root@localhost # httpd에서 오류가 발생했을 때 문제를 보고 하는 곳

<Directory /># 지정된 디렉토리및 모든 하위 디렉토리에 대한 구성 지시문 설정
AllowOverride none
Require all denied
</Directory>

DocumentRoot "/var/www/html" # httpd가 요청된 파일을 검색할 위치 결정
<Directory "/var/www/>
AllowOverride None
Require all granted
</Directory>

<Directory "/var/www/html">
Options Indexes
FollowSymLinks AllowOverride None
Require all granted
</Directory>


<IfModule dir_module> # 지정된 디렉토리가 요청될 때 사용할 파일을 지정
DirectoryIndex index.html
</IfModule>


<Files ".ht"> # <directory> 블록처럼 작동, 여기서는 와일드카드가 적용됨
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 # 로깅할 파일과 LogFormat을 결합하여 커스텀로그 저장
</IfModule>

AddDefaultCharset UTF-8 # text/plain 및 html/html 리소스의Content-Tpe 헤더에 charset 추가

IncludeOptional conf.d/*.conf # 일반적인 파일과 동일하게 작동하지만 파일이 없어도 오류가 # 생성되지 않음

✔️ Apache 실습

초기 설정

[root@server ~]# ip addr show ens33
[root@server ~]# nmcli con add con-name static ifname ens33 type ethernet ip4 192.168.6.100/24 gw4 192.168.6.254 
[root@server ~]# nmcli con up static
[root@server ~]# hostnamectl set-hostname server.test.example.com
[root@server ~]# vi /etc/hosts
[root@server ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-03-11 09:36:10 KST; 11s ago
     Docs: man:httpd(8)
           man:apachectl(8)




🔗 참고

728x90