root /var/www/html;</p> <p> # 设置密码来限制对munin网站的访问
location /munin {</p> <p> auth_basic "Administrator Login";
auth_basic_user_file /var/www/.htpasswd;
}</p> <p> #下面是给vhost开启了http_stub_status_module模块
#这段location其实放哪个server{}都可以,有的直接放到munin的虚拟机server{}一起 中</p> <p> location /nginx_status {</p> <p> stub_status on;
access_log off;
#只准本机访问/nginx_status中的request统计信息
#如果没有下面两行,那么,别人就可以使用
#http://test.dabu.info/nginx_status 看到nginx的request的信息了
#175.0.137.58是你的vps外网ip
allow 175.0.137.58;
deny all;</p> <p> }</p> <p> }
注 意:如果你将 location /nginx_status{}段与munin虚拟主机配置文件分开,放入单独的server{}段中时,那么就要先新建一个虚拟主机来开启了 http_stub_status_module模块,将其server{} 改成下面的样子:
复制代码 server
{
listen 127.0.0.1;
server_name localhost;</p>
<p> location /nginx_status {</p>
<p> stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}</p>
<p> }
同时将munin虚拟机的server段改成:
复制代码server {
listen 80 ;
access_log logs/server-access_log;</p>
<p> server_name test.dabu.info;</p>
<p> server_name_in_redirect off;
root /var/www/html;</p>
<p> location /munin {
auth_basic "Administrator Login";
auth_basic_user_file /var/www/.htpasswd;
}</p>
<p> }
此时,就只能本机访问 http://localhost/nginx_status 来得到nginx的request信息。
修改好后保存。接着重启nginx
复制代码 #service nginx restart
Apache:
复制代码# vi /etc/httpd/conf.d/munin.conf
在文件末尾添加下面的内容:
复制代码<Directory /var/www/html/munin/>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
</Directory>
同样要重启apache:
复制代码#service httpd restart
现在,你可以使用 http://test.dabu.info/munin 访问 munin的网页了。但是因为使用账号密码限制访问,所以,我们还要去设置访问密码。
设置访问网站的账户和密码:
yum安装munin默认的munin网站文件目录是在/var/www/html/munin中。为munin目录创建一个用户密码,执行命令:










