Apache 通过将响应头插入文件内容来破坏文件?

Apache 通过将响应头插入文件内容来破坏文件?

我有一个 Windows 共享,用户希望无需身份验证即可在浏览器中内部访问。我已将 Windows 共享挂载到我的 Ubuntu VM 上的 /mnt/Share。然后我将 DocumentRoot 指令设置为挂载点。

Apache 正确地为目录生成了索引页,但单击下载该共享内的 PDF 时,文件已损坏。打开从 Apache 下载的文件显示文件开头有额外的标题错误地保存在磁盘上:

 09:41:18 GMT
ETag: "c4d0-5a1968dbe5c3e"
Accept-Ranges: bytes
Content-Length: 50384
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/pdf

%PDF-1.6
%âãÏÓ
1 0 obj
<</AcroForm 5 0 R/Metadata 2 0 R/Outlines 6 0 R/Pages 3 0 R/Type/Catalog>>
endobj
5 0 obj

而在 /mnt 中查看完全相同的文件时,文件开始


%PDF-1.6
%âãÏÓ
1 0 obj
<</AcroForm 5 0 R/Metadata 2 0 R/Outlines 6 0 R/Pages 3 0 R/Type/Catalog>>
endobj
5 0 obj

我的 /etc/apache2/sites-available/000-default.conf 如下所示:


<VirtualHost [IP-redacted]:80>
        ServerAdmin [redacted]
        DocumentRoot /mnt/Share

        ServerName [IP-redacted]
        ServerAlias [redacted]

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyPreserveHost On

        # Geoserver
        ProxyPass /geoserver http://127.0.0.1:8080/geoserver
        ProxyPassReverse /geoserver http://127.0.0.1:8080/geoserver

        Alias "/Share" "/mnt/Share/"
        <Directory /mnt/Share >
                Options +Indexes -FollowSymLinks +MultiViews
                AllowOverride All
                Require all granted
                EnableSendfile Off
                IndexOptions +FancyIndexing
        </Directory>
</VirtualHost>

在研究这个问题时,我发现了一个可能的相关问题建议添加“EnableSendfile Off”,但这并没有解决我的问题。

该虚拟机恰好位于 Azure 中,并通过公司 LAN 的私有 VPN 进行访问,但其他一切正常,因此我目前没有怀疑存在任何网络问题。

更新:在测试更多文件时,我发现一些小型 XML 文件在下载时没有损坏。到目前为止,我尝试过的所有 PDF 和 TIF 都已损坏,如上所示,但到目前为止,我无法确定是文件类型还是文件大小导致了此问题。

更新 2:这是 Wireshark 中 HTTP 响应的第一个数据包: 损坏的数据包屏幕截图

答案1

我放弃了尝试让 Apache 工作,而是将其替换为 Nginx。这很有效,而且很简单

sudo systemctl stop apache2 && sudo apt install nginx

/etc/nginx/sites-enabled/default 的等效配置如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
        location /Share {
                alias /mnt/Share;
                autoindex on;
        }
        location /geoserver {
                proxy_set_header Host $host;
                proxy_pass http://127.0.0.1:8080/geoserver;
        }
}

相关内容