Nginx shows wrong time/timezone
Asked Answered
E

6

14

How to fix Nginx timezone? I've configured nginx to serve a directory but datetime of creation is one hour after my real time.

I've added to /etc/init.d/nginx

export TZ='Europe/Bratislava'

then

sudo service nginx reload
sudo service nginx restart

But it didn't help, there should be 14:19 instead of 13:19.

EDIT

Tried to change Ubuntu default timezone but the datetimes aren't changed.

sudo dpkg-reconfigure tzdata

enter image description here

Evacuee answered 7/12, 2018 at 13:27 Comment(0)
D
16

By default, nginx outputs the directory index in UTC time. If you want it to display the time in your local timezone, you should set the autoindex_localtime directive to on.

autoindex_localtime on
Dealt answered 7/12, 2018 at 13:31 Comment(1)
Note that it's not necessarily to be on location level, one could put it directly in server block on top.Barge
I
7

Firstly, you need to set your system timezone. You can use timedatectl list-timezones to get the names.

sudo timedatectl set-timezone Europe/Moscow

Secondly, set autoindex_localtime directive autoindex_localtime on; in nginx config file for your site, for example /etc/nginx/sites-avaliable/default. Put the directive before autoindex on;

server {
        listen 80;
        listen [::]:80;

        root /var/www/dir;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

        autoindex_localtime on;
        autoindex on;
}
Illmannered answered 12/5, 2021 at 11:19 Comment(0)
F
3

To change the timezone you can run the following command in your instance:

sudo dpkg-reconfigure tzdata

and then choose your preferred timezone.

Filial answered 16/2, 2019 at 6:1 Comment(0)
Q
0

Also the problem can be from php.ini. If you use php, change the time zone in [Date]

Qulllon answered 29/9, 2020 at 17:26 Comment(0)
M
0

enter image description here

look for /etc/init.d/ folder and open "nginx" file

$ sudo nano /etc/init.d/nginx and add TZ value for timezone

e.g export TZ = "Asia/Singapore"

Mini answered 16/10, 2022 at 6:48 Comment(0)
P
-1

check timezone of your system if require then set your own time zone then reboot . after reboot you will see correct time

Peppel answered 1/10, 2019 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.