【问题标题】:How to set date format for nginx $date_local如何为 nginx $date_local 设置日期格式
【发布时间】:2014-10-27 04:14:50
【问题描述】:

根据the docs,您可以使用命令config timefmt 在nginx 中设置日期格式,但我找不到任何关于在何处或如何设置的文档/示例。

默认显示类似“Sunday, 26-Oct-2014 21:05:24 Pacific Daylight Time”的字符串,我想将其更改为yyyyMMdd

如果有区别的话,我会在 Windows 上运行 nginx。

谢谢

【问题讨论】:

标签: nginx configuration config


【解决方案1】:

您一定没有正确阅读ngx_http_ssi_module documentation(尤其是它的'SSI Commands' section):它解释了命令格式。

您需要在希望解析 SSI 命令的上下文中将 ssi 指令设置为 on,然后您需要在其中提供包含这些命令的文件。

例如:

server {
    listen 8000;
    index index.txt;

    location / {
        ssi on;
    }
}

$date_local 变量声明必须使用config 命令对其进行配置,方法是设置其timefmt 参数。

您只需要提供将返回命令的文件,例如index.txt

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

timefmt 参数使用的格式是 strftime 标准 C 函数之一(如文档所述)。

【讨论】:

  • 我猜对于 php,它将是 /*# config timefmt="%A, %d-%b-%Y %H:%M:%S %Z" */,但它似乎没有工作。
  • SSI 解析 responses 并在那里解释(文本)命令。没有后端的概念,因此没有 PHP...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-01
  • 2014-06-02
  • 1970-01-01
  • 2015-01-05
  • 2017-06-26
  • 1970-01-01
相关资源
最近更新 更多