Symfony 对视频文件的响应 net::ERR_CONNECTION_RESET

Symfony Response net::ERR_CONNECTION_RESET on video file

在我的 IIS 机器上 (Windows 10) 它工作正常,但在托管服务器上不工作 (Windows 2008R2,IIS 7.5)。

托管服务器:通过 url 直接打开视频未显示在 Chrome 中。我在控制台 net::ERR_CONNECTION_RESET 中收到错误。但它在 IE 中工作。奇怪的是图像在 Chrome.

中工作

发生这种情况是因为我实施了一种安全机制:现在强制文件调用通过框架路由。该路由调用控制器,然后经过一些安全检查后,returns 文件为 BinaryFileResponse.

我不得不调整 webconfig(linux 上的 htaccess)。视频文件位于 data/content 文件夹下。

<rule name="ID:0001 Folder or File exists" enabled="true" stopProcessing="true">
    <match url="^(?!data/content)[a-z].*$" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
    </conditions>
    <action type="None" />
</rule>
<rule name="ID:0002 Datafolder" enabled="true" stopProcessing="true">
    <match url="^data/((?!content).)*$" />
    <action type="None" />
</rule>

我在 Internet 上搜索,发现的所有内容都是网络、防火墙或缓存方面可能存在的问题。但我不认为这是一个问题,因为它是因为我正在使用 Symfony BinaryFileResponse.

返回响应
$response = new BinaryFileResponse($webPath);
$response->setAutoEtag(true); // Needed for partial loading of video
$response->headers->set('Content-Type', 'video/mp4');
return $response;

网络headers:

General
    Request URL:http://foo.....bar.mp4
    Referrer Policy:no-referrer-when-downgrade
Request Headers
    Provisional headers are shown
    Accept-Encoding:identity;q=1, *;q=0
    chrome-proxy:frfr
    Range:bytes=0-
    Referer:http://foo.....bar.mp4
    User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36

IIS 7.5 的解决方案是 return 响应 header 中的更多信息。阅读 this.