天天看點

如何使用Apache控制指令檢查它的子產品是否已經啟用或加載

如何使用Apache控制指令檢查它的子產品是否已經啟用或加載

本篇中,我們會簡要地讨論 apache 伺服器前端以及如何列出或檢視已經啟用的 apache 子產品。

apache 基于子產品化的理念而建構,這樣就可以讓 web 管理者添加不同的子產品來擴充主要的功能及增強性能。

常見的 apache 子產品有:

mod_ssl – 提供了 https 功能。

mod_rewrite – 可以用正規表達式比對 url 樣式,并且使用 .htaccess 技巧來進行透明轉發,或者提供 http 狀态碼回應。

mod_security – 用于保護 apache 免于暴力破解或者 ddos 攻擊。

mod_status - 用于監測 apache 的負載及頁面統計。

在 linux 中 apachectl 或者 apache2ctl用于控制 apache 伺服器,是 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 

比如要啟動并檢查它的狀态,運作這兩個指令。如果你是普通使用者,使用 sudo 指令來以 root 使用者權限來運作:

$ 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 

當在直通模式下,apache2ctl 可以用下面的文法帶上所有 apache 的參數:

$ apachectl [apache-argument] 

$ apache2ctl [apache-argument] 

可以用下面的指令列出所有的 apache 參數:

$ apache2 help    [在基于debian的系統中] 

$ httpd help      [在rhel的系統中] 

檢查啟用的 apache 子產品

是以,為了檢測你的 apache 伺服器啟動了哪些子產品,在你的發行版中運作适當的指令,-t -d dump_modules 是一個用于顯示所有啟用的子產品的 apache 參數:

---------------  在基于 debian 的系統中 ---------------  

$ apache2ctl -t -d dump_modules    

或者  

$ apache2ctl -m  

---------------  在 rhel 的系統中 ---------------  

$ apachectl -t -d dump_modules    

$ httpd -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 子產品。記住你可以在下面的回報表中給我們留下你的問題或者留言。

作者:aaron kili

來源:51cto