Milano
Milano

Reputation: 18745

Nginx shows wrong time/timezone

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

Upvotes: 15

Views: 33889

Answers (6)

Nay Oo Kyaw
Nay Oo Kyaw

Reputation: 82

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"

Upvotes: 0

gman
gman

Reputation: 146

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;
}

Upvotes: 7

Vitalicus
Vitalicus

Reputation: 1379

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

Upvotes: 0

Ajay
Ajay

Reputation: 467

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

Upvotes: -1

SherylHohman
SherylHohman

Reputation: 17950

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

sudo dpkg-reconfigure tzdata

and then choose your preferred timezone.

Upvotes: 3

gpgekko
gpgekko

Reputation: 3616

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

Upvotes: 18

Related Questions