How to set date format for nginx $date_local

风流意气都作罢 提交于 2020-02-24 10:16:55

问题


According to the docs you can set the date format in nginx with the command config timefmt but I can't find any documentation/example on where or how to set that.

The default shows a string like "Sunday, 26-Oct-2014 21:05:24 Pacific Daylight Time" and I want to change it to yyyyMMdd

I'm running nginx on Windows if that makes a difference.

Thank you


回答1:


You must not have read the ngx_http_ssi_module documentation properly (especially its 'SSI Commands' section): it explains the commands format.

You need to set the ssi directive to on in the context you wish SSI commands to be parsed, then you need to serve files there which contains those commands.

For example:

server {
    listen 8000;
    index index.txt;

    location / {
        ssi on;
    }
}

The $date_local variable states that it must be configured with the config command, by settings its timefmt parameter.

You just need to serve files which will send commands back, such as index.txt:

<!--# config timefmt="%A, %d-%b-%Y %H:%M:%S %Z" -->

The format being used by the timefmt parameter is the one of the strftime standard C function (as the documentation states).



来源:https://stackoverflow.com/questions/26581098/how-to-set-date-format-for-nginx-date-local

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!