# Nginx access log using grok filter

**URL:** <https://discuss.elastic.co/t/nginx-access-log-using-grok-filter/324877>\
**Category:** Logstash\
**Created:** [February 7, 2023, 9:35am UTC](https://discuss.elastic.co/t/nginx-access-log-using-grok-filter/324877 "2023-02-07T09:35:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yc99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yc99/32/116857_2.png) [@yc99](https://discuss.elastic.co/u/yc99)\
**Post date:** [February 7, 2023, 9:35am UTC](https://discuss.elastic.co/t/nginx-access-log-using-grok-filter/324877/1 "2023-02-07T09:35:23Z")

</div>

My nginx access log format as below, there certain access log without the  
"$request\_time" "$http\_x\_forwarded\_for" $http\_host ' field, therefore, for certain access log, the grok filter not working, is there anyway to automatic fill the field with - so that other field of the message will be process?

```auto
 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$request_time" "$http_x_forwarded_for" $http_host ';

```

```auto
 grok {
        match => { "message" => "%{IPORHOST:remote_ip} - %{DATA:user_name} \[%{HTTPDATE:time}\] \"%{WORD:method}%{DATA:url} HTTP/%{NUMBER:http_version}\" %{NUMBER:response_code} %{NUMBER:body_sent:bytes} \"%{DATA:referrer}\" \"%{DATA:agent}\" \"%{NUMBER:request_time}\" \"%{DATA:http_x_forwarded_for}\" %{IPORHOST:http_host} " }
        remove_field => "message"
       
    }

```

---

<div class="post-metadata">

**Author:** ![Grant\_Hope](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grant_hope/32/117492_2.png) [@Grant\_Hope](https://discuss.elastic.co/u/Grant_Hope)\
**Post date:** [February 21, 2023, 12:36am UTC](https://discuss.elastic.co/t/nginx-access-log-using-grok-filter/324877/2 "2023-02-21T00:36:14Z")

</div>

You could have a catch all %{GREEDYDATA:payload} at the end of the grok options.

Something like  
` match => { "message" => ["%{IPORHOST:remote_ip} - %{DATA:user_name} \[%{HTTPDATE:time}\] \"%{WORD:method}%{DATA:url} HTTP/%{NUMBER:http_version}\" %{NUMBER:response_code} %{NUMBER:body_sent:bytes} \"%{DATA:referrer}\" \"%{DATA:agent}\" \"%{NUMBER:request_time}\" \"%{DATA:http_x_forwarded_for}\" %{IPORHOST:http_host} ", %{GREEDYDATA:payload} ] }`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 21, 2023, 12:36am UTC](https://discuss.elastic.co/t/nginx-access-log-using-grok-filter/324877/3 "2023-03-21T00:36:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
