CentOS下改变系统和nginx的时区 

我的VPS是在美国的,所以默认时区当然不可能是中国标准时间(CST),我也一直没改。不过这几天,我发现了问题,就是我的nginx是使用的我系统的默认时区(UTC),而我是使用nginx做我的ftp用户目录文件的展示的,也就是说,我上传文件的时间和用户在nginx上看到的时间是不吻合的,之间相差了8个小时~

这的确很坑爹~我决定把时区改回来。在CentOS下,有tzselect命令可以改。直接运行即可:
[root@PowerPC ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
##选择所在洲
#? 5
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
##选择所在国家
#? 9
Please select one of the following time zone regions.
1) east China - Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of Tibet & Xinjiang
5) west Tibet & Xinjiang
##选择所在城市区域
#? 1

The following information has been given:

China
east China - Beijing, Guangdong, Shanghai, etc.

Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Sat Aug 13 19:32:00 CST 2011.
Universal Time is now: Sat Aug 13 11:32:00 UTC 2011.
Is the above information OK?
1) Yes
2) No
##确认修改
#? 1

You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

至此,时区修改完成。

不过我打印了下"date"好像还是没有即时生效?!
又查了下,看来只好手动改了~

首先,删除位于/etc 下的localtime 文件。
rm -rf /etc/localtime

之后,创建一个同名的软连接到/usr/share/zoneinfo/Asia 下的Shanghai文件。
ls -s /etc/localtime /usr/share/zoneinfo/Asia/Shanghai

即可。

查看效果:
[root@PowerPC ~]# ls /etc/local* -lh
lrwxrwxrwx 1 root root 33 Aug 13 19:41 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
[root@PowerPC ~]# date
Sun Aug 21 17:14:19 CST 2011
[root@PowerPC ~]# date -u
Sun Aug 21 09:14:21 UTC 2011
[root@PowerPC ~]#

看,这样一来,时区立马生效了~

不过,系统的时区是改过来了,nginx的时区好像还是UTC.这是肿么回事?

难道要重启生效? killall nginx 杀死nginx进程
再启动,问题依旧。

难道要在配置文件指定? 根据nginx官方wiki(地址:http://wiki.nginx.org/CoreModule#env)的说明,在nginx.conf 里加上一句:

# set timezone
env TZ=CST;

重启,还是不行。

在系统变量里添加$TZ为CST,
export TZ="CST"

重启,依旧不行~

杯具~

在以“nginx change timezone”为关键词搜索的时候,看到了nginx 更新日志里面有这么一行:

*) Feature: now nginx takes into account a time zone change while
reconfiguration on FreeBSD and Linux.


难不成nginx只会在编译时候才会读取系统时区?以后要改变时区只能重新编译???!!

至于你们信不信,反正我是不信~囧rz

针对这个问题,我已经在nginx的官方邮件列表提问了(地址见:http://mailman.nginx.org/pipermail/nginx/2011-August/028562.html),现在只有等官方的回答了~
[ ] ( 3951 次浏览 ) 永久链接 ( 3 / 2470 )

<< <上一页 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 下一页> >>