Nginx 系统日志发布请求

问题描述

现在我的 nginx 日志保存在文件中。但是可以将日志发送到自定义 url (http://myapi.com/save-logs) 吗?我需要将所有 nginx 日志保存在我的数据库中。

目前我的配置文件是这样的:

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
worker_rlimit_nofile 4096;

events {
  multi_accept on;
  use epoll;
  worker_connections 1024;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  error_log /var/log/nginx/error.log warn;
  access_log /var/log/nginx/access.log;
  open_file_cache max=5000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  server_tokens off;
  types_hash_max_size 2048;
  keepalive_requests 1000;
  keepalive_timeout 5;
  server_names_hash_max_size 512;
  server_names_hash_bucket_size 64;
  client_max_body_size 100m;
  client_body_buffer_size 256k;
  reset_timedout_connection on;
  client_body_timeout 10;
  send_timeout 2;
  gzip on;
  gzip_static on;
  gzip_comp_level 5;
  gzip_min_length 256;
  gzip_http_version 1.1;
  gzip_proxied any;
  gzip_vary on;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
  gzip_disable "msie6";
  proxy_max_temp_file_size 0;

  upstream proj {
    server clickhouse:8123;
  }

  upstream grafana {
    server grafana:3000;
  }

  server {
    listen 8888;
    server_name 127.0.0.1;
    root /var/www;
    proxy_set_header Host $host;
    location / {
      proxy_pass http://proj;
      proxy_set_header Host $host;
      add_header Cache-Control "no-cache" always;
    }
  }

  server {
    listen 9999;
    server_name 127.0.0.1;
    root /var/www;
    proxy_set_header Host $host;
    location / {
      proxy_pass http://grafana;
      proxy_set_header Host $host;
      add_header Cache-Control "no-cache" always;
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)