Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx/PHP:Nginx在发送Etag头时没有返回304响应_Php_Caching_Header_Nginx_Etag - Fatal编程技术网

Nginx/PHP:Nginx在发送Etag头时没有返回304响应

Nginx/PHP:Nginx在发送Etag头时没有返回304响应,php,caching,header,nginx,etag,Php,Caching,Header,Nginx,Etag,我正在尝试使用etag和nginx(1.2.1)服务器来理解本地缓存,该服务器将php的请求重定向到phpcgideamon 下面是我的simple index.php: <?php header('Cache-Control: public'); header('Etag:"5954c6-10f4-449d11713aac0"'); echo microtime(true); 但我的web服务器不返回304: HTTP/1.1 200 OK Server: nginx/1.2.2 D

我正在尝试使用etag和nginx(1.2.1)服务器来理解本地缓存,该服务器将php的请求重定向到phpcgideamon

下面是我的simple index.php:

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

echo microtime(true);
但我的web服务器不返回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匹配进行比较,并返回304响应,因为它们是相同的

我错在哪里? 我是否应该将Etag与PHP脚本中的If None进行比较,因为nginx(或Apache)本身无法完成任务

问候,,
Manu

如果您自己使用php实现此功能,您还负责发送未修改的304


因此,请将If None Match头与您的ETag进行比较,并使用header()发回304。

或者您也可以通过黑客攻击nginx来为您执行此操作。问题是nginx不“知道”当前的ETag,因此nginx仍然必须先执行实际的PHP请求,以找出ETag头是什么。这听起来是个坏主意。当然,但是nginx可以在将响应头返回到客户端之前处理这些响应头。后处理。@hakre根据RFC它不能,因为nginx不是原始服务器。@Evert FYI:AFAIK,该功能包括在nginx 1.7.3以后的版本中,以及etag生成。一些PHP代码,etag兼容
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