簡體   English   中英

Nginx從訪問日志中排除使用map和regex捕獲URL中一部分單詞的URL

[英]Nginx exclude from access log an URL using map and regex to catch a part of word in URL

我有帶有配置的Nginx 1.17,成功從日志中排除了POST請求方法

map $request_method $loggable {
default       1;
POST          0;
}
access_log /var/log/nginx/nginx_access.log main if=$loggable;

我嘗試在下面進行配置,以排除不記錄任何單詞“ rsey”的一部分且不區分大小寫的URL,例如JerSey2018

map_hash_bucket_size 128;
map $request_uri $loggable {
    (.*?)rsey(.*?) 0;
    default 1;
    }
map $request_method $loggable {
default       1;
POST          0;
}
access_log /var/log/nginx/nginx_access.log main if=$loggable;

但是使用此配置NGINX仍然從日志中排除POST請求,但仍在日志中寫入http://example.com/ID-16409696108601-JerSey2018-report.html之類的URL,因此我的map / regex規則無法捕獲必需的內容-LOG例子->

example.com 88.256.54.27 - - [01/Aug/2019:06:52:00 -0500]  "GET /ID-16409696108601-JerSey2018-report.html HTTP/1.1" 200 3366 "http://example.com/sitemap.xml" "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"

感謝您嘗試的任何提示和想法...也許有人可以指出我上述配置中的錯誤?

***過了一會兒-與Nginx地圖打架太累了,似乎最好使用這樣的詞來逐個單詞捕捉位置(盡管也無法正常工作)

location ~ /(.*)rsey(.*)/ {
    access_log off;
 }

因此,對於任何想法,現在請嘗試在此行中嘗試在Nginx中捕獲REAL通配符

location ~ /(.*)rsey(.*)/ {

您不能從兩個map塊中控制相同的變量。 但是您可以將第一個map的值用作第二個map的默認值。

例如:

map $request_uri $loguri {
    default  1;
    ~*rsey   0;
}
map $request_method $loggable {
    default  $loguri;
    POST     0;
}
access_log /var/log/nginx/nginx_access.log main if=$loggable;

有關詳細信息,請參見此文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM