我有一个Flask应用程序,通过x-accel-redirect将应该提供静态文件的请求重定向到Nginx.有时,这些下载将在完成之前被切断.例如,通过cURL,我会看到:
curl http://my_server/some_static_file.tar > temp.tar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
77 14.4G 77 11.2G 0 0 55.8M 0 0:04:24 0:03:25 0:00:59 58.9M
curl: (18) transfer closed with 3449105332 bytes remaining to read
这似乎更常见于非常大的文件(10gb),但我已经看到它也发生在~90mb的较小文件上. Nginx访问日志显示来自和提供不同,不完整数据量的请求:
1.2.3.4 - - [18/Apr/2017:01:16:26 +0000] "GET /some/flask/static/file/path HTTP/1.1" 200 15146008576 "-" "curl/7.38.0" "5.6.7.8"
1.2.3.5 - - [18/Apr/2017:01:16:29 +0000] "GET /some/flask/static/file/path HTTP/1.1" 200 15441739776 "-" "curl/7.38.0" "6.7.8.9"
errors.log没什么用处.
我的相关烧瓶配置如下:
response = make_response('')
response.headers.set('X-Accel-Redirect','/_special_Nginx_path/' + file_name)
response.headers.set('Content-Disposition','attachment',filename=file_name)
# have tried both with and without setting content-length
response.headers.set('Content-Length',os.path.getsize(file_path))
try:
response.mimetype = mimetypes.guess_type(file_name)[0]
if not response.mimetype:
response.mimetype = 'application/octet-stream'
except AttributeError:
response.mimetype = 'application/octet-stream'
return response
我的相关Nginx配置如下(运行我的烧瓶应用程序的uWSGI服务器运行在127.0.0.1:1234):
location / {
proxy_pass http://127.0.0.1:1234;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /_special_Nginx_path {
internal;
alias /path/to/static/files;
}
2018/10/28 14:20:24 [crit] 5432#5432: *75 pwritev() “/var/lib/Nginx/uwsgi/1/00/0000000001” Failed (28: No space left on device) while reading upstream,
首先,确定哪个分区没有可用空间.您可以通过在终端中键入以下命令来执行此操作:
df -h
您现在将在屏幕上看到以下详细信息:
File system. Size. Used. Available. Used. Mounted on.
浏览分区详细信息并检查是否有任何分区的磁盘空间使用率达到100%.
找到分区后,打开它并删除无用的文件,以释放磁盘空间并解决问题.
如果分区安装在系统内存上(由TMPFS目录指示),请运行以下命令以卸载它.
Umount path_to_the_directory.
为防止将来设备错误留下空间,请编辑Nginx配置文件(或您网站的配置文件)并增加密钥区域的值.
用户面临问题,因为他们将操作系统配置为从RAM提供缓存文件.虽然这可以快速提高站点的性能,但它可以减少服务器上运行的其他应用程序可用的RAM量,并导致内存不足错误.
如果您的服务器使用SSD而不是HDD,则不必将分区安装到系统内存中.
感谢blog帮我…