Nginx在Ubuntu上的性能监控实践
一 快速检查与内置状态页
sudo nginx -V 2>&1 | grep -- '--with-http_stub_status_module'location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1; # 建议仅内网或本机访问
deny all;
}
sudo nginx -t && sudo systemctl reload nginxcurl http://127.0.0.1/nginx_status二 日志分析与可视化
tail -f /var/log/nginx/access.logawk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -nrsudo apt-get install goaccessgoaccess /var/log/nginx/access.log -o /var/www/html/report.html --log-format=COMBINED三 指标采集与可视化平台
nginx-prometheus-exporter -nginx.scrape-uri=http://127.0.0.1/nginx_statusscrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'nginx'
static_configs:
- targets: ['localhost:8080']
四 系统级资源与健康检查
top / htopfree -hiostat -x 1(需 sudo apt-get install sysstat)netstat -tulpen | grep ':80\|:443'vmstat 1五 关键指标与告警建议