Hello!
2012/11/6 郝洪标:
> 下面是我测试用的代码,加上没什么效果
> #content_by_lua '
> #if ngx.var.http_if_modified_since ~= nil then
> # ngx.exit(304)
> #end
> #';
>
> 也许是没有这个变量,
>
考虑下面这个比较完整的例子:
location = /t {
content_by_lua '
if ngx.var.http_if_modified_since ~= nil then
ngx.exit(304)
end
ngx.say("we miss it!")
';
}
在我本地(Linux x86_64, Fedora 17),使用 ngx_lua 0.7.3 + nginx 1.2.4 运行之,然后使用
curl 进行测试,结果如下:
$ curl -i -H 'If-Modified-Since: blah' localhost:8080/t
HTTP/1.1 304 Not Modified
Server: nginx/1.2.4
Date: Tue, 06 Nov 2012 19:01:14 GMT
Content-Length: 0
Connection: keep-alive
$ curl -i localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.2.4
Date: Tue, 06 Nov 2012 19:01:39 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
we miss it!
一个建议是请使用 curl 这样的简单工具测试你的接口(以避免浏览器缓存之类因素的干扰),并提供更多更详细的信息 :)
Best regards,
-agentzh