웹사이트 검색

Linux에서 Apache 웹 서버를 관리하는 데 유용한 명령


이 튜토리얼에서는 개발자나 시스템 관리자가 알아야 하고 이러한 명령을 바로 사용할 수 있어야 하는 가장 일반적으로 사용되는 Apache(HTTPD) 서비스 관리 명령 중 일부를 설명합니다. SystemdSysVinit에 대한 명령을 모두 표시합니다.

또한 읽어 보세요: 모든 Linux 사용자가 알아야 할 가장 많이 사용되는 Nginx 명령 10가지

다음 명령은 root 또는 sudo 사용자로 실행되어야 하며 CentOS, RHEL과 같은 모든 Linux 배포판에서 작동해야 합니다. Fedora DebianUbuntu.

아파치 서버 설치

Apache 웹 서버를 설치하려면 표시된 대로 기본 배포 패키지 관리자를 사용하십시오.

sudo apt install apache2	    [On Debian/Ubuntu]
sudo yum install httpd	    [On RHEL/CentOS]
sudo dnf install httpd	    [On Fedora 22+]
sudo zypper install apache2	    [On openSUSE]

아파치 버전 확인

Linux 시스템에 설치된 Apache 웹 서버 버전을 확인하려면 다음 명령을 실행하십시오.

sudo httpd -v
OR
sudo apache2 -v
샘플 출력
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

Apache 버전 번호와 컴파일 설정을 표시하려면 표시된 대로 -V 플래그를 사용하세요.

sudo httpd -V
OR
sudo apache2 -V
샘플 출력
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09
Server's Module Magic Number: 20120211:24
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Apache 구성 구문 오류 확인

구문 오류가 있는지 Apache 구성 파일을 확인하려면 서비스를 다시 시작하기 전에 구성 파일의 유효성을 확인하는 다음 명령을 실행하십시오.

sudo httpd -t
OR
sudo apache2ctl -t
샘플 출력
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using linux-console.net. 
Set the 'ServerName' directive globally to suppress this message
Syntax OK

아파치 서비스 시작

Apache 서비스를 시작하려면 다음 명령을 실행하세요.

------------ On CentOS/RHEL ------------ 
sudo systemctl start httpd     [On Systemd]
sudo service httpd start 	 [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl start apache2   [On Systemd]
sudo service apache2 start     [On SysVInit]

Apache 서비스 활성화

이전 명령은 그동안 Apache 서비스만 시작합니다. 시스템 부팅 시 자동 시작을 활성화하려면 다음 명령을 실행합니다.

------------ On CentOS/RHEL ------------ 
sudo systemctl enable httpd     [On Systemd]
sudo chkconfig httpd on 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl enable apache2   [On Systemd]
sudo chkconfig apache2 on       [On SysVInit]

아파치 서비스 다시 시작

Apache를 다시 시작하려면(서비스를 중지한 후 시작) 다음 명령을 실행하세요.

------------ On CentOS/RHEL ------------ 
sudo systemctl restart httpd     [On Systemd]
sudo service httpd restart 	   [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl restart apache2   [On Systemd]
sudo service apache2 restart     [On SysVInit]

Apache 서비스 상태 보기

Apache 서비스 런타임 상태 정보를 확인하려면 다음 명령을 실행하십시오.

------------ On CentOS/RHEL ------------ 
sudo systemctl status httpd     [On Systemd]
sudo service httpd status 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl status apache2   [On Systemd]
sudo service apache2 status     [On SysVInit]

Apache 서비스 다시 로드

Apache 서버 구성을 변경한 경우 다음 명령을 실행하여 서비스에 구성을 다시 로드하도록 지시할 수 있습니다.

------------ On CentOS/RHEL ------------ 
sudo systemctl reload httpd     [On Systemd]
sudo service httpd reload 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl reload apache2   [On Systemd]
sudo service apache2 reload     [On SysVInit]

Apache 서비스 중지

Apache 서비스를 중지하려면 다음 명령을 사용하세요.

------------ On CentOS/RHEL ------------ 
sudo systemctl stop httpd       [On Systemd]
sudo service httpd stop 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
sudo systemctl stop apache2     [On Systemd]
sudo service apache2 stop     [On SysVInit]

Apache 명령 도움말 표시

마지막으로 다음 명령을 실행하면 systemd에서 Apache 서비스 명령에 대한 도움말을 얻을 수 있습니다.

sudo httpd -h
OR
sudo apache2 -h		
OR
systemctl -h apache2	
샘플 출력
Usage: httpd [-D name] [-d directory] [-f file]
             [-C "directive"] [-c "directive"]
             [-k start|restart|graceful|graceful-stop|stop]
             [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in  directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules 
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

systemctl에 대한 자세한 내용은 Linux에서 'Systemctl'을 사용하여 'Systemd' 서비스 및 장치를 관리하는 방법을 참조하여 찾을 수 있습니다.

다음 Apache 관련 기사를 읽고 싶을 수도 있습니다.

  1. Apache 웹 서버 성능을 향상시키는 5가지 팁
  2. Apache 웹 서버 로드 및 페이지 통계를 모니터링하는 방법
  3. "Apache GUI" 도구를 사용하여 Apache 웹 서버를 관리하는 방법
  4. Linux에서 Apache HTTP 포트를 변경하는 방법
  5. 13가지 Apache 웹 서버 보안 및 강화 팁
  6. Mod_Security 및 Mod_evasive 모듈을 사용하여 무차별 공격 또는 DDoS 공격으로부터 Apache를 보호하세요

지금은 여기까지입니다! 이 문서에서는 Apache 시작, 활성화, 재시작, 중지를 포함하여 가장 일반적으로 사용되는 Apache/HTTPD 서비스 관리 명령에 대해 설명했습니다. 질문이나 의견이 있으면 언제든지 아래 피드백 양식을 통해 문의하실 수 있습니다.