查看已安装的nginx是否包含stub_status模块
- /usr/local/nginx/sbin/nginx -V
- nginx version: Nginx/1.2.0
- configure arguments: --with-http_stub_status_module
确定支持stub_status模块后编辑修改nginx.conf
- vim /usr/local/nginx/conf/nginx.conf
- //server{} 中,需要已经加入如下内容
- location / {
- root html;
- index index.php index.html index.htm;
- location /nginx_status {
- stub_status on; //这个选项参数就是在编译时对stub_status模块的支持,如果不编译加入则会在启动nginx时有警告信息
- access_log off;
- }
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$ {
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- // 去掉如下内容的注释,这里是对php的支持,注意文件路径
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
- include fastcgi_params;
- }
重启Nginx服务器
- /usr/local/nginx/sbin/nginx -s reload
设置定时收集数据
- crontab -e
- * * * * * root /usr/sbin/nginx-collect
- */10 * * * * root /usr/sbin/nginx-graph
访问页面http://域名/index.php,nginx的连接数如下图
nginx请求数如下图


