如何打开apache的server-status和server-info

百里秋月
2023-12-01



首先 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/


 类似资料: