无法从 wordpress 网站提供图像 - 响应格式错误

无法从 wordpress 网站提供图像 - 响应格式错误

我正在尝试使用 Azure Files 支持的 PersistentVolume 在 Azure 上的 Traefik 后面部署 Wordpress。在大多数情况下,它都可以正常工作。我可以设置 wordpress、配置它、从外部访问它、进行内容编辑等。

该 docker 镜像是 Hub 上的官方镜像(https://hub.docker.com/_/wordpress)。我做的唯一更改是告诉 MYSQL 客户端使用 SSL,否则其他一切都是原始的。

奇怪的是,没有图片能够正确显示。Apache 认为它能正常显示,但 Traefik 拒绝响应,认为其格式错误。具体来说,它收到的是“字节”而不是响应代码,然后断开连接,向浏览器返回 500。

我将其追溯到 Apache 服务器本身,但还是被难住了。以下是我所看到的 - 再次强调,仅针对图像。

这是从 AKS 上的容器内部运行的。

root@wordpress-7bd5ccfd77-drm96:/var/www/html# curl --http0.9 -iv --raw http://localhost:80/wp-includes/images/spinner.gif
*   Trying ::1:80...
* Connected to localhost (::1) port 80 (#0)
> GET /wp-includes/images/spinner.gif HTTP/1.1
> Host: localhost
> User-Agent: curl/7.74.0
> Accept: */*
>
ges: bytes
Content-Length: 3656
Content-Type: image/gif

GIF89a...

如你所见,HTTP 响应的一部分截断。

如果我做同样的事情但要求获取页面内容,我不会遇到任何问题。

root@wordpress-7bd5ccfd77-drm96:/var/www/html# curl --http0.9 -iv --raw http://localhost:80/
*   Trying ::1:80...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Mon, 17 Jan 2022 09:15:33 GMT
...

如果我将同一个文件远程复制出 pod,或者通过 Azure Files 文件共享远程复制,它会按预期通过,因此它不会在卷上损坏,也不会因卷的安装方式而损坏。

kubectl cp it-scribe-wordpress/wordpress-794cbff687-ts6q9:/var/www/html/wp-includes/images/spinner.gif ./spinner.gif
tar: Removing leading `/' from member names

我得到了一个非常有用的 spinner.gif。

据我所知,这种情况只发生在图像上。任何想法都将不胜感激。

伊恩

编辑:我使用 --http0.9 的原因是,如果没有它,curl 会提前失败,并且不会让我看到响应。该标志只会影响 curl 的处理,而不会影响请求主体。这是一个没有该标志的示例。

root@wordpress-7bd5ccfd77-drm96:/var/www/html# curl -iv --raw http://localhost:80/wp-includes/images/spinner.gif
*   Trying ::1:80...
* Connected to localhost (::1) port 80 (#0)
> GET /wp-includes/images/spinner.gif HTTP/1.1
> Host: localhost
> User-Agent: curl/7.74.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed

* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed

答案1

我认为 Azure Files、AKS CSI 和 Apache 之间的交互存在问题。我只能使用 Azure Files 重现此行为 - 其他形式的卷挂载(磁盘、容器文件、NFS)均按预期工作。

有证据表明其他人也遇到过这种情况:https://github.com/Azure/AKS/issues/2614

我已经使用 NFS 挂载进行了尝试。

答案2

该问题可能不是 WordPress 特有的,更多的是 Apache 和 Azure Files 的问题。

使用 NGINX 不会发生此问题。我建议切换到 NGINX 和 PHP-FPM。

无论如何,由于 pod 通过 SMB 连接到 Azure Files,快速谷歌搜索就会发现许多人遇到与 Apache 和 SMB 相同的问题。

一个快速简单的解决方案是打开 EnableSendFile。

看 -https://httpd.apache.org/docs/current/mod/core.html#EnableSendfile

您可以通过向 .htaccess、主 apache 配置或 vhost 配置添加以下行来执行此操作。

EnableSendFile On

相关内容