TransWikia.com

Nginx syslog post request

Stack Overflow Asked by Andreas Hunter on March 5, 2021

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;
    }
  }
}

One Answer

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.

Answered by user9989615 on March 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP