首先 server-status和server-info 依賴於/usr/local/apache2/conf/extra/httpd-info.conf
於是去/usr/local/apache2/conf/extra/httpd-info.conf中修改配置,可以修改如下:
#
# Get information about the requests being processed by the server
# and the configuration of the server.
#
# Required modules: mod_status (for the server-status handler),
# mod_info (for the server-info handler)
#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost
</Location>
#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On
#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".example.com" to match your domain to enable.
#
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from localhost
</Location>
本地測試的情況可以設定為監控localhost,另外要將ExtendedStatus On開啟
然後我們需要保證apache已經安裝mod_status和mod_info模組,可以用以下命令查看:
apache2 -l 或者 httpd -l
得到結果如下:
root@junjie:/home/andy/Downloads/httpd-2.2.25# apache -l
Compiled in modules:
core.c
mod_authn_file.c
mod_authn_default.c
mod_authz_host.c
mod_authz_groupfile.c
mod_authz_user.c
mod_authz_default.c
mod_auth_basic.c
mod_cache.c
mod_mem_cache.c
mod_include.c
mod_filter.c
mod_log_config.c
mod_env.c
mod_mime_magic.c
mod_expires.c
mod_headers.c
mod_usertrack.c
mod_unique_id.c
mod_setenvif.c
mod_version.c
mod_proxy.c
mod_proxy_connect.c
mod_proxy_ftp.c
mod_proxy_http.c
mod_proxy_scgi.c
mod_proxy_ajp.c
mod_proxy_balancer.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_asis.c
mod_info.c
mod_negotiation.c
mod_dir.c
mod_alias.c
mod_rewrite.c
mod_so.c
可以看到已經安裝載入的apache模組
如果結果中沒有mod_status.so和mod_info.so,那麼你需要重新編譯安裝apache,例如:
./configure --enable-module=so --enable-info
重新編譯安裝apache,注意make clean
如果上面一切執行完畢之後,我們就需要修改配置:httpd.conf
# Real-time info on requests and configuration
Include conf/extra/httpd-info.conf
然後我們重啟apache就可以訪問了:
http://localhost/server-status
http://localhost/server-info
還有一些小技巧:http://www.ccvita.com/333.html
參考:
http://wenku.baidu.com/view/5201570902020740be1e9b2e.html
http://man.chinaunix.net/newsoft/ApacheManual/install.html
http://man.chinaunix.net/newsoft/ApacheManual/install.html
http://snowolf.iteye.com/blog/743611
http://jingfeng198.blog.163.com/blog/static/4625592012729112223350/
http://httpd.apache.org/docs/2.2/mod/mod_status.html
http://blog.csdn.net/jackyrongvip/article/details/5667692
本以為這樣就沒問題了,可是實際環境中果然還是有問題:
例如我的網站host是www.example.com
那麼訪問www.example.com/server-status的時候出現錯誤提示:
Forbidden
You don't have permission to access /server-status on this server.
好吧,因為我的host下面有.htaccess路由,是這樣:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
這樣訪問肯定不行,所以我們修改為:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !server-status
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
~
讓其可以被訪問,現在就可以了!
此處.htaccess規則參考:http://www.freesharing.info/rewritecond-request_filename-f/