2

我正在尝试使用 ETags 和 nginx(1.2.1)服务器来理解本地缓存,它将 php 的请求重定向到 php-cgi 守护进程。

这是我的简单 index.php :

<?php
header('Cache-Control: public');
header('Etag:"5954c6-10f4-449d11713aac0"');

echo microtime(true);

在第二次请求之后,我的浏览器发送一个 If-None-Match 标头:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Host:cache.loc
If-None-Match:"5954c6-10f4-449d11713aac0"

但我的网络服务器不返回 304 :

HTTP/1.1 200 OK
Server: nginx/1.2.2
Date: Thu, 12 Jul 2012 11:46:03 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.3.12
Cache-Control: public
Etag: "5954c6-10f4-449d11713aac0"
Cache-Control: public

除非我误解了,否则我的服务器应该将 Etag 与发送的 If-None-Match 进行比较并返回 304 响应,因为它们是相同的。

我哪里错了?我是否应该在我的 PHP 脚本中将 Etag 与 If-None-Match 进行比较,因为 nginx(或 Apache)本身不会完成这项工作?

问候,马努

4

1 回答 1

3

如果您自己使用 php 实现此功能,还需要负责发送 304 Not Modified。

So compare the If-None-Match header with your ETag, and use header() to send back the 304.

于 2012-07-12T11:55:09.690 回答