duanlian1978 2017-05-16 07:53
浏览 90

Apache mod-x-sendfile但是用于远程url

I'm writing a PHP application where users can download some files. Not all files can be downloaded by all users and some complicated rights-checking is going on behind the scenes.

Because of this rights-checking I don't want to expose the url where the file is actually located, as I want to force the user to always use the endpoint where his credentials are verified.

In my current implementation this is all written using PHP (fread, etc). In order to minimize memory consumption this is implemented as a stream, such that PHP mostly acts as a proxy.

But I would like to only use PHP for the authentication, and then use Apache2 for the actual hosting. Looking around for options it seemed X-Sendfile would be an ideal fit.

The only issue in using X-Sendfile is that it only works for local files, and my files are on a remote storage server (not my webserver).

So essentially I have a direct link to my storage server (which I want to hide):

https://storage.example.com/the-pet-goat.pdf

And the public link the user interacts with:

https://www.example.com/randomized-id/download

and I would like that when the user goes to https://www.example.com/randomized-id/download its credentials are checked and if successful he should be (invisibly) redirected to the file on the storage server.

Is there a way to achieve this (using Apache)? I've found X-Accel-Redirect, but that is for NGinx

I've found a similar question here on SO: Alternative to X-sendfile in Apache for sending file given a URL? but that one is specifically targeting S3, Apache (and Ruby on Rails), while this question is more generic for Apache.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口