![Nginx 返回 200 而不是 206](https://linux22.com/image/773302/Nginx%20%E8%BF%94%E5%9B%9E%20200%20%E8%80%8C%E4%B8%8D%E6%98%AF%20206.png)
我设置了 Nginx 服务器 (openresty),其中包含大文件。当客户端需要范围文件时,Nginx 返回 200,而不是 206。
这是我的 curl 测试的示例:
curl -v -I -r 0- -X GET http://172.29.22.11/myBigFile.bin
* Trying 172.29.22.11:80...
* TCP_NODELAY set
* Connected to 172.29.22.11 (172.29.22.11) port 80 (#0)
> GET /myBigFile.bin HTTP/1.1
> Host: 172.29.22.11
> Range: bytes=0-
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
< Connection: keep-alive
Connection: keep-alive
< Expires: Wed, 21 Dec 2022 09:10:00 GMT
Expires: Wed, 21 Dec 2022 09:10:00 GMT
< Cache-Control: max-age=31536000
Cache-Control: max-age=31536000
< Access-Control-Allow-Headers: *
Access-Control-Allow-Headers: *
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< myCacheStatus: HIT
myCacheStatus: HIT
< Pragma: public
Pragma: public
< Cache-Control: public
Cache-Control: public
<
* Excess found: excess = 448 url =/myBigFile.bin A (zero-length body)
* Connection #0 to host 172.29.22.11 left intact
我该如何定义 Nginx 来返回正确的 206?
----- 添加我的配置 -----
location / {
internal;
proxy_cache my_cache;
proxy_cache_key $uri;
# set the ceching time for 200 respinse -> to 7 days
proxy_cache_valid 200 7d;
# Clear flags I dont want
more_clear_headers 'Access-Control-Allow-Headers';
more_clear_headers 'Access-Control-Allow-Origin';
more_clear_headers 'access*';
more_clear_headers 'content-disposition';
more_clear_headers 'Date';
more_clear_headers 'x-proxy-cache';
more_clear_headers 'Server';
# add headers to handle CORS
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
# to reduce Bandwisth I use compression
gzip on;
# set up the proxy, and instruct it to cech even if thre is no Cache-Control
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_cache_lock on;
proxy_cache_lock_timeout 0s;
proxy_cache_lock_age 200s;
proxy_cache_use_stale updating;
# the run reverse proxy
proxy_pass http://0.0.0.0:3000;
# set local ceching on the client side currently we will start at 365 days
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}