1

I am running nginx with default log format

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

It prints the access log in following format

1.2.3.4 - - [27/Mar/2021:09:39:43 +0000] "GET /text.txt HTTP/1.1" 200 315 "-" "curl/7.55.1" "-"

However I want the logs to print time in UTC +05:30 which is not the local time of the server. I tried adding env "TZ=Asia/Kolkata"; at the top of nginx.conf but it didn't work. Please suggest how to do this.

Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66
  • This will not work as the time opereations in NGINX are based on some generic C functions. But What about using njs to create a new Date-Variable and use this in your log format? https://nginx.org/en/docs/njs/compatibility.html; search for Date. If thats a thing I can write an answer about how to implement. – Timo Stark Mar 27 '21 at 10:35

1 Answers1

2

Regarding setting timezone in Nginx logs: Works fine; just need to set the "TZ" environment variable for nginx daemon (e.g. in the script that launches it). Or if you're using Docker, set it in the Dockerfile (or in the "environment" in docker-compose.yml file if you're using that).

Bhoopesh
  • 21
  • 3