From 68b25db0c2bd87e796c7811e3fcd202914b91d56 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Thu, 6 Nov 2025 12:02:36 +0900 Subject: [PATCH] Fixed conf error --- nginx.conf | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/nginx.conf b/nginx.conf index d469ee8..b68d5f4 100644 --- a/nginx.conf +++ b/nginx.conf @@ -42,15 +42,47 @@ http { fe80::/10 0; # Link-local } + ## + # AI bot block map (optional; enforce in server with: if ($block_ai) { return 403; }) + ## + map $http_user_agent $block_ai { + default 0; + ~*(GPTBot|ChatGPT-User|OAI-SearchBot|CCBot|Claude(Bot)?|PerplexityBot|Bytespider|Google-Extended|Amazonbot|DataForSeoBot|facebookexternalhit|DuckAssist|YouBot) 1; + } + ## # Logging (JSON) ## log_format json escape=json - '{ "time":"$time_iso8601", "remote_addr":"$remote_addr", "request":"$request", ' - '"status":$status, "body_bytes_sent":$body_bytes_sent, ' - '"referer":"$http_referer", "ua":"$http_user_agent", ' - '"request_time":$request_time, "upstream_time":"$upstream_response_time", ' - '"host":"$host", "uri":"$uri" }'; + '{' + '"time":"$time_iso8601",' + '"req_id":"$msec-$connection-$request_length",' + '"is_external":$is_external,' + '"is_ai_bot":$block_ai,' + '"client_ip":"$remote_addr",' + '"client_port":"$remote_port",' + '"xff":"$http_x_forwarded_for",' + '"scheme":"$scheme",' + '"host":"$host",' + '"method":"$request_method",' + '"uri":"$uri",' + '"query":"$query_string",' + '"proto":"$server_protocol",' + '"status":$status,' + '"ref":"$http_referer",' + '"ua":"$http_user_agent",' + '"req_bytes":$request_length,' + '"body_bytes_sent":$body_bytes_sent,' + '"bytes_sent":$bytes_sent,' + '"req_time":$request_time,' + '"upstream_addr":"$upstream_addr",' + '"upstream_status":"$upstream_status",' + '"upstream_connect_time":"$upstream_connect_time",' + '"upstream_header_time":"$upstream_header_time",' + '"upstream_response_time":"$upstream_response_time",' + '"ssl_protocol":"$ssl_protocol",' + '"ssl_cipher":"$ssl_cipher"' + '}'; access_log /var/log/nginx/access.json json if=$is_external; @@ -72,17 +104,9 @@ http { limit_req_zone $binary_remote_addr zone=api_rps:10m rate=5r/s; limit_conn_zone $binary_remote_addr zone=perip:10m; - ## - # AI bot block map (optional; enforce in server with: if ($block_ai) { return 403; }) - ## - map $http_user_agent $block_ai { - default 0; - ~*(GPTBot|ChatGPT-User|OAI-SearchBot|CCBot|ClaudeBot|PerplexityBot) 1; - } - ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; -} \ No newline at end of file +}