0

Now my nginx logs save on the file. But it's possible send logs to custom url (http://myapi.com/save-logs) ? I need save all my nginx logs on my database.

Currently my config file looks like this:

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;
    }
  }
}
Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125

1 Answers1

0

I think this is possible. According to http://nginx.org/en/docs/syslog.html, the server directive could let you specify where you want to log your info to.