如何使用Apache控制命令檢查它的模塊是否已經(jīng)啟用或加載
本篇中,我們會簡要地討論 Apache 服務(wù)器前端以及如何列出或查看已經(jīng)啟用的 Apache 模塊。
Apache 基于模塊化的理念而構(gòu)建,這樣就可以讓 web 管理員添加不同的模塊來擴(kuò)展主要的功能及增強(qiáng)性能。
常見的 Apache 模塊有:
- mod_ssl – 提供了 HTTPS 功能。
- mod_rewrite – 可以用正則表達(dá)式匹配 url 樣式,并且使用 .htaccess 技巧來進(jìn)行透明轉(zhuǎn)發(fā),或者提供 HTTP 狀態(tài)碼回應(yīng)。
- mod_security – 用于保護(hù) Apache 免于暴力破解或者 DDoS 攻擊。
- mod_status - 用于監(jiān)測 Apache 的負(fù)載及頁面統(tǒng)計。
在 Linux 中 apachectl 或者 apache2ctl用于控制 Apache 服務(wù)器,是 Apache 的前端。
你可以用下面的命令顯示 apache2ctl 的使用信息:
- $ apache2ctl help
- 或者
- $ apachectl help
- Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]
- [-C "directive"] [-c "directive"]
- [-k start|restart|graceful|graceful-stop|stop]
- [-v] [-V] [-h] [-l] [-L] [-t] [-S]
- 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 settings (currently only vhost settings)
- -S : a synonym for -t -D DUMP_VHOSTS
- -t -D DUMP_MODULES : show all loaded modules
- -M : a synonym for -t -D DUMP_MODULES
- -t : run syntax check for config files
apache2ctl 可以工作在兩種模式下,SysV init 模式和直通模式。在 SysV init 模式下,apache2ctl 用如下的簡單的單命令形式:
- $ apachectl command
- 或者
- $ apache2ctl command
比如要啟動并檢查它的狀態(tài),運行這兩個命令。如果你是普通用戶,使用 sudo 命令來以 root 用戶權(quán)限來運行:
- $ sudo apache2ctl start
- $ sudo apache2ctl status
- tecmint@TecMint ~ $ sudo apache2ctl start
- AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1\. Set the 'ServerName' directive globally to suppress this message
- httpd (pid 1456) already running
- tecmint@TecMint ~ $ sudo apache2ctl status
- Apache Server Status for localhost (via 127.0.0.1)
- Server Version: Apache/2.4.18 (Ubuntu)
- Server MPM: prefork
- Server Built: 2016-07-14T12:32:26
- -------------------------------------------------------------------------------
- Current Time: Tuesday, 15-Nov-2016 11:47:28 IST
- Restart Time: Tuesday, 15-Nov-2016 10:21:46 IST
- Parent Server Config. Generation: 2
- Parent Server MPM Generation: 1
- Server uptime: 1 hour 25 minutes 41 seconds
- Server load: 0.97 0.94 0.77
- Total accesses: 2 - Total Traffic: 3 kB
- CPU Usage: u0 s0 cu0 cs0
- .000389 requests/sec - 0 B/second - 1536 B/request
- 1 requests currently being processed, 4 idle workers
- __W__...........................................................
- ................................................................
- ......................
- Scoreboard Key:
- "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
- "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
- "C" Closing connection, "L" Logging, "G" Gracefully finishing,
- "I" Idle cleanup of worker, "." Open slot with no current process
當(dāng)在直通模式下,apache2ctl 可以用下面的語法帶上所有 Apache 的參數(shù):
- $ apachectl [apache-argument]
- $ apache2ctl [apache-argument]
可以用下面的命令列出所有的 Apache 參數(shù):
- $ apache2 help [在基于Debian的系統(tǒng)中]
- $ httpd help [在RHEL的系統(tǒng)中]
檢查啟用的 Apache 模塊
因此,為了檢測你的 Apache 服務(wù)器啟動了哪些模塊,在你的發(fā)行版中運行適當(dāng)?shù)拿睿?t -D DUMP_MODULES 是一個用于顯示所有啟用的模塊的 Apache 參數(shù):
- --------------- 在基于 Debian 的系統(tǒng)中 ---------------
- $ apache2ctl -t -D DUMP_MODULES
- 或者
- $ apache2ctl -M
- --------------- 在 RHEL 的系統(tǒng)中 ---------------
- $ apachectl -t -D DUMP_MODULES
- 或者
- $ httpd -M
- $ apache2ctl -M
- [root@tecmint httpd]# apachectl -M
- Loaded Modules:
- core_module (static)
- mpm_prefork_module (static)
- http_module (static)
- so_module (static)
- auth_basic_module (shared)
- auth_digest_module (shared)
- authn_file_module (shared)
- authn_alias_module (shared)
- authn_anon_module (shared)
- authn_dbm_module (shared)
- authn_default_module (shared)
- authz_host_module (shared)
- authz_user_module (shared)
- authz_owner_module (shared)
- authz_groupfile_module (shared)
- authz_dbm_module (shared)
- authz_default_module (shared)
- ldap_module (shared)
- authnz_ldap_module (shared)
- include_module (shared)
- ....
就是這樣!在這篇簡單的教程中,我們解釋了如何使用 Apache 前端工具來列出啟動的 Apache 模塊。記住你可以在下面的反饋表中給我們留下你的問題或者留言。