大网数据广告活动
服务器运维问答

NGINX SSI working fine, but LAST_MODIFIED returning "(none)"?

· 52CE 我爱测

I have NGINX SSI working fine in the virtualHosts file (code below) but LAST_MODIFIED is returning "(none)", although the NGINX docs for SSI state that the ssi_last_modified directive appeared in version 1.5.1 (we’re running vers…

问题原文

原帖链接 · Dave Everitt · CC BY-SA 4.0

I have NGINX SSI working fine in the virtualHosts file (code below) but LAST_MODIFIED is returning "(none)", although the NGINX docs for SSI state that the ssi_last_modified directive appeared in version 1.5.1 (we’re running version 1.14.2).

VirtualHost file:

…
  location / {
    ssi on;
    ssi_last_modified on;
    …
  }
…

and in the .html file:

<!--#if expr="$footer_id='blackfooter'" --><div id="blackfooter"><!--#else --><div id="footer"><!--#endif -->
    <!--#config timefmt="%A %d %B %Y" --><p>Updated: <!--#echo var="LAST_MODIFIED" --> | Today: <!--#echo var="DATE_LOCAL" --></p>
</div>

So for now, I've resorted to JavaScript:

<!--#if expr="$footer_id='blackfooter'" --><footer id="blackfooter"><!--#else --><footer><!--#endif -->
    <!--#config timefmt="%A %d %B %Y" --><p>Updated: <span id="updated"></span> | Today: <!--#echo var="DATE_LOCAL" --></p>
</footer>
<script>
    let lastmod = new Date(document.lastModified);
    updated.innerHTML = lastmod.toString().substring(4,15);
</script>

Why is NGINX delivering other documented SSI functionality, but not LAST_MODIFIED in the header?

The only possible clue I found was that the sub_filter_last_modified is mentioned in the docs for the NGINX ngx_http_sub_module but AFAIK (and I'm not NGINX specialist) I'm not sure that helps much.

已采纳解答

原帖链接 · mforsetti · CC BY-SA 4.0

Why is NGINX delivering other documented SSI functionality, but not LAST_MODIFIED in the header?

Because nginx haven't fully implement SSI anyway. Quoting the docs:

Currently, the list of supported SSI commands is incomplete.

For a list of supported SSI commands and variables, check nginx's source here.


Edit:

If complete SSI support is desired, try using Apache httpd behind nginx.

according to the NGIX (sic) docs (see the link in my post)

Here's direct quote from ssi_last_modified docs circa July 21st, 2021:

Allows preserving the Last-Modified header field from the original response during SSI processing to facilitate response caching.

By default, the header field is removed as contents of the response are modified during processing and may contain dynamically generated elements or parts that are changed independently of the original response.

By default, when responding to a request for a static file, nginx adds Last-Modified HTTP response header.

When using SSI, nginx remove this header on purpose because nginx is generating the page dynamically instead of returning a static file, therefore adding a Last-Modified response header is pointless.

ssi_last_modified directive re-adds Last-Modified HTTP response header according to SSI script file timestamp.

In no way it said that this directive adds LAST_MODIFIED variable to nginx's SSI.

LAST_MODIFIED should still be supported

AFAIK, there's no standard, nor RFCs, that could be relied upon to completely implement SSI. Arguably, docs to mod_include could be such standard, but again, it's only a manual to another product. Let me know if there's such standard and I'll amend this answer.

You'll have better chance resolving this problem by submitting a feature request to nginx's Trac.

Tangent: even if it's supported, if you add LAST_MODIFIED, should its value be the timestamp of the SSI script, or server timestamp; since the HTML response is generated on-the-fly instead of directly read from a file.

This is for legacy sites I've moved across to NGINX from Apache. Some large sites still use SSI, and it's a useful lightweight way approach, avoiding PHP etc.

I doubt those large sites still use SSI behind the scenes. At this point, SSI is a legacy framework with a lot of alternatives available.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-07-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。