Nginx 系统日志发布请求
Posted
技术标签:
【中文标题】Nginx 系统日志发布请求【英文标题】:Nginx syslog post request 【发布时间】:2021-02-08 05:56:29 【问题描述】:现在我的 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;
【问题讨论】:
【参考方案1】:我认为这是可能的。根据http://nginx.org/en/docs/syslog.html,server
指令可以让您指定要将信息记录到的位置。
【讨论】:
以上是关于Nginx 系统日志发布请求的主要内容,如果未能解决你的问题,请参考以下文章