如何配置apache或nginx服务器以使用我选择的算法发送Etag标头(即不涉及inode,mtime或size)?有没有其他方法来编译新的C模块?
答案 0 :(得分:5)
在Apache中,ETags are handled as a core feature。 ETag被计算为几个值的散列。您可以使用FileETag
或httpd.conf
文件中的.htaccess
指令来定义要包含在哈希中的值的条件行为,但正如您所指出的,您的选项仅限于:< / p>
INode
- 您提供的特定服务器上的文件的索引节点号MTime
- 您的文件服务器的时间戳(以毫秒为单位)Size
- 文件大小(以字节为单位)All
- 以上所有None
- 以上都不是如果你想要真正的自定义ETag生成,你肯定最好写一个Apache模块。但是,如果您需要快速而肮脏的修复,则可以通过将请求路由到PHP脚本并在脚本中附加Etag
标头来生成自己的标记。您的httpd.conf
或.htaccess
文件中的路线可能如下所示:
RewriteCond %{REQUEST_FILENAME} \.png$ # This example looks for .png requests
RewriteRule ^(.*)$ /gentag.php?path=$1 [B] # ...and routes them to a PHP script
PHP脚本可能如下所示:
<?
$path = $_GET['path']; // Grab the filepath from GET params
$cont = file_get_contents($path); // Get file contents to hash
$hash = crc32($cont); // Create your own ETag hash however you like
header("Etag: $hash"); // Send the custom Etag header
echo $cont; // Dump the file contents to output
?>
答案 1 :(得分:0)
在this公关中有一些评论可以满足您的需求。它不是您选择的算法,而是MD5,非常可靠。
您会注意到它们提供了两个选项。
ETag
标头计算中(不要将其用作Last-Modified
标头,因为将来可能会使用它。)