nginx 如何修复'失败(22:无效的参数),而发送响应到客户端'

pinkon5k  于 2023-11-17  发布在  Nginx
关注(0)|答案(2)|浏览(296)

Nginx无法读取文件时,有多个挂载点,有不同的扇区大小时,使用directio。
我们的服务器在Nginx的根文件夹下安装了不同的硬盘驱动器。我们所有的旧磁盘都有512的扇区大小,当我们更换磁盘时,Nginx突然无法从该磁盘读取文件。
服务器上似乎没有什么问题,我们可以列出/读取文件没有问题,但Nginx不能。在error_log中向客户端发送响应时显示失败(22:无效参数)。

[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client
[crit] pread() "/str/.../dsf13at.mp4" failed (22: Invalid argument) while sending response to client

字符串

硬盘信息

硬盘驱动器512

Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


4096的新硬盘

Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

pieyvz9o

pieyvz9o1#

问题是Nginx使用了512的directio_alignment,但当硬盘大小为4096时,这似乎不起作用。
directio_alignment设置为4k解决了这个问题,Nginx现在可以从512和4096扇区的驱动器读取数据。

Nginx配置:

aio threads;
aio_write on;
directio 8M;
directio_alignment 4k;

字符串

shyt4zoc

shyt4zoc2#

我在nginx 1.22.1 / Debian 12上遇到了同样的问题。
我刚刚关闭了sendfile,它工作了:

#sendfile on;
sendfile off;

字符串

相关问题