
URI의 특정 쿼리 매개변수가 Nginx 액세스 로그에 기록되지 않도록 제외할 수 있는지 궁금합니다.
현재 구성은 다음과 같습니다.
log_format main '$remote_addr - $remote_user [$time_local] $host "$request" '
'$status $body_bytes_sent $request_time "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
요청 경로에 관계없이 "latitude" 매개변수가 기록에서 제외되기를 원한다고 가정해 보겠습니다(또는 난독화하는 것이 바람직함). 제외할 수 있다는 것을 알고 있습니다.모두"$request"를 예를 들어 "$request_method $uri"로 변경하여 쿼리 매개변수를 잃습니다.모두내가 원하는 것이 아닌 매개변수입니다.
업데이트:
나는 GET /index.html?latitude=43.4321&otherkey=value HTTP/1.1
다음과 같이 난독화하고 싶습니다.GET /index.html?latitude=******&otherkey=value HTTP/1.1
답변1
GET /index.html?key=latitude&otherkey=value HTTP/1.1
된다
GET /index.html?key=***&otherkey=value HTTP/1.1
코드는 다음과 같습니다.
log_format main '$remote_addr - $remote_user [$time_local] $host "$customrequest" '
'$status $body_bytes_sent $request_time "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
map $request $customrequest {
~^(.*)(latitude)(.*)$ "$1***$3";
default $request;
}
다음과 같이 여러 키워드를 추가할 수 있습니다.~^(.*)(latitude|dell|inspiron)(.*)$
편집하다:
주석에 사양을 지정한 후 정규식을 수정해야 합니다
GET /index.html?latitude=5570&otherkey=value HTTP/1.1
.
GET /index.html?latitude=***&otherkey=value HTTP/1.1
map $request $customrequest {
~^(.*)([\?&]latitude=)([^&]*)(.*)$ "$1$2***$4";
default $request;
}