mod_xsendfile不会CGI和工作的mod_rewrite [英] mod_xsendfile won't work with CGI and mod_rewrite

查看:197
本文介绍了mod_xsendfile不会CGI和工作的mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 Apache模块xsendfile 获取文件流中有更好的表现。
问题是,它的只是工作,如果我不使用PHP的CGI版本,如果我不使用重写规则作为我的网址。

I am trying to use the apache module xsendfile to get a better performance during file streaming. The problem is, that it is just working if I DO NOT use PHP as CGI Version AND if I DO NOT USE rewrite rules for my urls.

在浏览器中调用这个一会工夫:

Calling this one in the Browser will work:

http://subdomain.domain.de/image.php

这人会给我一个404:

This one will give me a 404:

http://subdomain.domain.de/rewrittenImageUrl

重写规则工作的权利。 404错误由xsendfile模块触发。
如果我在.htaccess中加入一个R的规则(像在提出这个问题)将再次工作,因为我重定向到以上给出的第一个地址。但是重定向是不是我想要的。

The rewrite rules are working right. The 404 error is triggered by the xsendfile module. If I add a "R" to the rule in the htaccess (like suggested in this question) it will work again, because I am redirected to the first address given above. But redirecting is not what I want.

我还观看了有关的符号链接这个帖子,但我认为这不能成为我的帖子的解决方案,只要我用用GETENV('DOCUMENT_ROOT')产生的绝对路径?这pathes不应该使用任何符号链接,不是吗​​?还是我在这一点上失去了一些东西?

I also watched out this post about symlinks, but I think this could not be a solution for my post as long as I use absolute paths generated by using getenv('document_root')? This pathes shouldn't use any symbolic links, do they? Or am I missing something at this point?

如果我切换PHP模式的CGI版本,我会得到一个0字节的文件。这似乎是像服务器相同的行为将不xsendfile任何安装反应。

If I switch the PHP mode to the cgi version I will get a 0 byte file. This seems to be the same behaviour like the server would react without any installation of xsendfile.

我已经更新了模块的最新版本。
测试还没有任何成功的绝对和相对的链接。
除了那<一href=\"http://stackoverflow.com/questions/8707944/xsendfile-not-working-php-apache-cpanel\">Deactivating输出COM pression 没有工作。

I have already updated the module to the latest version. Also tested absolute and relative links without any success. In addition to that Deactivating the output compression didn't work.

要在这里完成给定的信息是PHP code我使用的:

To complete the given information here is the PHP code I am using:

ini_set('zlib.output_compression', 'Off');
$realImagePath = getenv('document_root')."fixedRelativeImagePathNoParamsNeeded.jpg";

$imageInfos = @getimagesize($realImagePath);
header('Content-Type: '.$imageInfos['mime']);   
header("X-Sendfile: $realImagePath");
exit();

任何人有一个线索?

Anyone has a clue?

第二个问题就解决了​​
我不知道为什么,但它是在Apache的配置开启xsendfile而不是使用htaccess文件后工作。 (我会在下面添加一个答案soons与其他问题解决了。)

The second problem is solved: I don't know why but it's working after turning on xsendfile in the apache config instead of using the htaccess file. (I will add an answer below as soons as the other problem is solved, too.)

在除了第一个:
首先,我并没有在httpd.conf添加任何选项,因为它应该与标准配置中工作。反正我现在问我的提供商,为项目的绝对路径添加到XSendFilePath的白名单作为一个全球性的设置。 这暂时解决了问题1.用mod_rewrite的。但是,这似乎只是不适合我的情况真正的解决办法,因为我在服务器上运行许多不同的项目,每一个分开的下载路径。所以,我要问,我的供应商每次我开始一个新项目的新路径添加到配置。
我仍然只是无法使用X-发送文件与mod_rewrotite虽然我应该能够访问文档根目录没有任何额外的设置。

In addition to the first one: First I did not add any options in the httpd.conf as it should be working with the standard configuration. Anyway I now asked my provider to add the absolute project path to the whitelist of XSendFilePath as a global setting. This temporarily solved the 1. Problem with mod_rewrite. But this just seems to be not a real solution for my situation, because I am running many different projects on the server, each with a separated download path. So I would need to ask my provider to add a new path to the config each time I am starting a new project. I still just can't use x-sendfile with mod_rewrotite although I should have access to the document root without any extra settings.

推荐答案

mod_xsendfile 并从构建相对路径绝对路径<一个href=\"https://github.com/nmaier/mod_xsendfile/blob/f181be5964a994a636d612dfa1b17394c3d8b116/mod_xsendfile.c#L182\"相对=nofollow>基于所述请求URI 的,这可能会在实际上是在某些情况下,一个子请求。这并不总是产生预期的结果。

mod_xsendfile does construct absolute paths from relative paths based on the request URI, which might in fact be a sub-request in some cases. This does not always produce the results you expect.

因此,我总是用绝对URI在 X-SENDFILE 头。

上面的第二个结果是,构建的路径,不一定是你所期望的,自动白名单的目录,你不要指望,而那当然不是白名单,你本来期望的目录。

The second consequence of the above is that the constructed path, not necessarily being what you expect, auto-whitelist a directory you do not expect, while then of course not whitelisting the directory you would have expected.

因此,总是白名单的URI。

Therefore, always white-list URIs.

在短,阿帕奇可能不会考虑同一目录是一个请求的当前工作目录,你(或后端* CGI)。只有重写增加了混乱。

In short, Apache might not consider the same directory to be the current working directory of a request as you (or a backend *CGI). Rewriting only adds to the confusion.

我其实考虑彻底放弃了相对路径/自动白名单的东西这个原因,因为它可以固然很混乱,而且也记录下。
我想这是一个有点晚了完全放弃它,但我至少应该将其标记去precated。

I actually considered dropping the relative paths/auto-whitelist stuff altogether for this reasons, because it can be admittedly very confusing, and is also under-documented. I guess it is a little late to drop it entirely, but I should at least mark it deprecated.

这篇关于mod_xsendfile不会CGI和工作的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆