Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add X-Accel-Redirect support for Nginx (a sibiling of X-Sendfile)
Browse files Browse the repository at this point in the history
For it to work you have to modify your nginx conf to send X-Accel-Mapping header using
-> proxy_set_header X-Accel-Mapping /var/www/ajaxplorer/data/=/data/;
or
-> fastcgi_param X-Accel-Mapping /var/www/ajaxplorer/data/=/data/;
and you have to use the "internal" keyword
-> location ~ /data/ { internal; }

The X-Accel-Mapping idea come from the rails world
  • Loading branch information
Etienne CHAMPETIER committed Jul 18, 2013
1 parent 19df26c commit 67549c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -1236,6 +1236,22 @@ function readFile($filePathOrData, $headerType="plain", $localName="", $data=fal
header('Content-Disposition: attachment; filename="' . basename($filePathOrData) . '"');
return;
}
if($this->getFilteredOption("USE_XACCELREDIRECT", $this->repository->getId()) && $this->wrapperClassName == "fsAccessWrapper" && array_key_exists("X-Accel-Mapping",$_SERVER)){
if(!$realfileSystem) $filePathOrData = fsAccessWrapper::getRealFSReference($filePathOrData);
$filePathOrData = str_replace("\\", "/", $filePathOrData);
$filePathOrData = SystemTextEncoding::toUTF8($filePathOrData);
$mapping = explode('=',$_SERVER['X-Accel-Mapping']);
$replacecount = 0;
$accelfile = str_replace($mapping[0],$mapping[1],$filePathOrData,$replacecount);
if($replacecount == 1){
header("X-Accel-Redirect: $accelfile");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($accelfile) . '"');
return;
} else {
AJXP_Logger::logAction("error","Problem with X-Accel-Mapping for file $filePathOrData");
}
}
$stream = fopen("php://output", "a");
if($realfileSystem){
AJXP_Logger::debug("realFS!", array("file"=>$filePathOrData));
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/access.fs/manifest.xml
Expand Up @@ -14,6 +14,7 @@
<global_param name="PROBE_REAL_SIZE" type="boolean" label="CONF_MESSAGE[Real Size Probing]" description="CONF_MESSAGE[Use system command line to get the filesize instead of php built-in function (fixes the 2Go limitation)]" default="false"/>
<global_param name="USE_POSIX" type="boolean" label="CONF_MESSAGE[Use POSIX]" description="CONF_MESSAGE[Use php POSIX extension to read files permissions. Only works on *nix systems.]" default="false"/>
<global_param name="USE_XSENDFILE" type="boolean" label="CONF_MESSAGE[X-SendFile Active]" description="CONF_MESSAGE[Delegates all download operations to the webserver using the X-SendFile header. Warning, this is an external module to install for Apache. Module is active by default in Lighttpd. Warning, you have to manually add the folders where files will be downloaded in the module configuration (XSendFilePath directive)]" default="false"/>
<global_param name="USE_XACCELREDIRECT" type="boolean" label="CONF_MESSAGE[X-Accel-Redirect Active]" description="CONF_MESSAGE[Delegates all download operations to nginx using the X-Accel-Redirect header. Warning, you have to add some configuration in nginx, like X-Accel-Mapping]" default="false"/>
<global_param group="MIXIN_MESSAGE[Metadata and indexation]" name="DEFAULT_METASOURCES" type="string" label="MIXIN_MESSAGE[Default Metasources]" description="MIXIN_MESSAGE[Comma separated list of metastore and meta plugins, that will be automatically applied to all repositories created with this driver]" mandatory="false" default="metastore.serial,meta.filehasher,index.lucene"/>
</server_settings>
<class_definition filename="plugins/access.fs/class.fsAccessDriver.php" classname="fsAccessDriver"/>
Expand All @@ -38,4 +39,4 @@
</hooks>
</registry_contributions>
<class_stream_wrapper filename="plugins/access.fs/class.fsAccessWrapper.php" classname="fsAccessWrapper" protocol="ajxp.fs"/>
</ajxpdriver>
</ajxpdriver>

0 comments on commit 67549c7

Please sign in to comment.