Connect NGINX to Watchlog
This guide explains how to connect NGINX to Watchlog so you can monitor metrics such as request status codes, response times, and active connections.
Prerequisite: Watchlog Agent installed
Make sure the Watchlog Agent is already installed on your server. If it is not installed yet, follow the installation guide first and then return to this page.
Step 1 – Configure NGINX
Add the following configuration to your NGINX config to expose the status endpoint and enable Watchlog-specific access logs.
- Enable the NGINX status endpoint (
stub_status):
server {
listen 127.0.0.1:8080; # Change IP/port if needed
server_name localhost;
location /nginx_status {
stub_status on;
# Optionally restrict access:
# allow 127.0.0.1;
# deny all;
}
}
- Add the Watchlog log format and use it for the access log:
log_format watchlogFormat '$remote_addr - $remote_user [$time_local] '
'"$request" "$scheme://$host$request_uri" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe $ssl_protocol $ssl_cipher';
access_log /var/log/nginx/access.log watchlogFormat;
- Test and reload NGINX:
sudo nginx -t
sudo systemctl reload nginx
Step 2 – Update Watchlog Agent integration config
Tell the Watchlog Agent to monitor NGINX by updating the integration.json file.
Ubuntu
Go to /opt/watchlog-agent, open the integration.json file and update your configuration:
cd /opt/watchlog-agent
sudo vim integration.json
# (Make your changes and save)
Add or update the NGINX section as follows:
{
"monitor": true,
"service": "nginx",
"accessLog": "/var/log/nginx/access.log",
"nginx_status_url": "http://localhost:8080/nginx_status"
}
Note: All integration configurations are stored in this file.
Step 3 – Reload the Watchlog Agent
After saving integration.json, reload the Watchlog Agent with PM2:
sudo pm2 reload watchlog-agent
Step 4 – Verify the integration in Watchlog
- Log in to the Watchlog dashboard.
- Go to the NGINX integration section.
- Confirm that:
- Metrics from
/nginx_status(connections, requests, etc.) are visible. - Access logs from
/var/log/nginx/access.logare being ingested and displayed.
- Metrics from
If you do not see data after a few minutes:
- Check that NGINX is receiving traffic.
- Re-check the
access_logpath andwatchlogFormatin your NGINX config. - Ensure the
nginx_status_urlis reachable from the server running the Watchlog Agent.
