You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 7下Nginx Amplify无法采集访问/错误日志指标求助

Troubleshooting Nginx Amplify Log Metric Collection on CentOS 7

Hey there, let's tackle this issue where Nginx Amplify is reporting system metrics just fine but failing to pull data from your access and error logs—especially since the same setup works on Ubuntu. The culprit is almost certainly a CentOS-specific security or configuration quirk, so let's walk through the key checks step by step:

1. Check SELinux (Most Likely Culprit)

CentOS enables SELinux by default, while Ubuntu typically leaves it disabled. SELinux can block the Amplify agent from reading Nginx log files even if file permissions look correct.

  • First, verify SELinux status:
    sestatus
    
    If the output shows Current mode: enforcing, try temporarily disabling it to test:
    setenforce 0
    
    Wait 5-10 minutes, then check if Amplify starts picking up log metrics. If it works, you'll need to adjust SELinux contexts permanently:
    • Apply the correct context to your Nginx log directory:
      chcon -R -t httpd_log_t /path/to/nginx/logs/
      
    • To make this change persistent across reboots:
      semanage fcontext -a -t httpd_log_t "/path/to/nginx/logs(/.*)?"
      restorecon -Rv /path/to/nginx/logs/
      

2. Verify Amplify Agent's User/Group Permissions

Even if log files have readable permissions, the Amplify agent might be running as a user that doesn't have access to them.

  • Check which user the Amplify agent runs as:
    ps aux | grep amplify-agent
    
  • Compare that to the permissions on your Nginx logs:
    ls -l /path/to/nginx/access.log /path/to/nginx/error.log
    
  • If the agent's user isn't in the group that owns the logs, add it (e.g., if logs are owned by the nginx group):
    usermod -aG nginx amplify-agent
    systemctl restart amplify-agent
    

3. Validate Nginx Log Format Compatibility

Amplify requires specific log fields to parse metrics correctly. Make sure your Nginx log format includes all necessary data points.

  • Check your log_format directive in /etc/nginx/nginx.conf (or included config files). The official recommended format for Amplify is:
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
    
  • Ensure your server blocks are using this format for access logs:
    access_log /var/log/nginx/access.log main;
    
    Restart Nginx after any changes:
    systemctl restart nginx
    

4. Inspect Amplify Agent Logs for Errors

The agent's own logs will often tell you exactly why it can't read the logs.

  • Check the agent log file (usually at /var/log/amplify-agent/amplify-agent.log):
    grep -i "log\|error\|permission" /var/log/amplify-agent/amplify-agent.log
    
  • Look for messages like cannot open log file or permission denied—these will point directly to the issue.

5. Confirm Nginx Config Path in Amplify Agent

If you installed Nginx from source or a non-standard repo, the Amplify agent might not be finding your Nginx config file automatically.

  • Edit the agent config at /etc/amplify-agent/agent.conf and set the correct path to your Nginx main config:
    nginx.config_path = /etc/nginx/nginx.conf
    
  • Restart the agent to apply changes:
    systemctl restart amplify-agent
    

6. Check Systemd Service Logs

Use systemd's journal to monitor the Amplify agent in real-time for any runtime issues:

journalctl -u amplify-agent -f

This will show you live logs as the agent runs, which can help catch transient errors that might not show up in the main log file.


内容的提问来源于stack exchange,提问作者Venkata S S K M Chaitanya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:18:27