openresty禁用304 Not Modified,



先看一段代码:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}

http {

    log_format  main  '$msec $status $request $request_time '
                      '$http_referer $remote_addr [ $time_local ] '
                      '$upstream_response_time $host $bytes_sent '
                      '$request_length $upstream_addr';

    access_log  logs/access.log main buffer=32k flush=1s;


    server {
        listen 80;

        location / {
            content_by_lua '
                ngx.header["Content-Type"] = "text/html"
                ngx.header["Etag"] = "663b92165e216225df78fbbd47c9c5ba"
                ngx.header["Last-Modified"] = "Fri, 12 May 2016 18:53:33 GMT"
                local data = "hello world"
                ngx.status = ngx.HTTP_OK
                ngx.print(data)
                ngx.exit(ngx.HTTP_OK)
            ';
            expires 24h;
            #if_modified_since off;
        }

    }

}


在浏览器多次运行结果:



分析:

虽然显式的设置了响应码HTTP 200,但是nginx默认会开启304的判断(如果浏览器把If-Modified-Since和If-None-Match带上来),

如果不需要内置304响应,则可以选择禁用:

Syntax:	if_modified_since off | exact | before;
Default:	
if_modified_since exact;
Context:	http, server, location
This directive appeared in version 0.7.24.


原文出自:http://blog.csdn.net/daiyudong2020/article/details/53224470


End;



相关内容

    暂无相关文章