diff options
author | Andrew Dolgov <[email protected]> | 2018-08-20 13:00:13 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-08-20 13:00:13 +0300 |
commit | acb5bc12c86ad1cd9d8b2a4742005546f8bf9e02 (patch) | |
tree | a4592760b44412621d41de8ddd5a15a4f154f5d5 |
initial
-rw-r--r-- | README.md | 21 | ||||
-rw-r--r-- | init.php | 46 |
2 files changed, 67 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebc0611 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# README + +## Installation + +Git clone to tt-rss/plugins.local/nginx_xaccel + +## Configuration + +Setup redirect prefix for nginx (should lead to tt-rss base directory) +via NGINX_XACCEL_PREFIX in ```config.php```: + +``` + define('NGINX_XACCEL_PREFIX', '/tt-rss'); +``` + +``` + location /tt-rss/cache { + aio threads; + internal; + } +``` diff --git a/init.php b/init.php new file mode 100644 index 0000000..b024288 --- /dev/null +++ b/init.php @@ -0,0 +1,46 @@ +<?php +class Nginx_Xaccel extends Plugin { + private $host; + + function about() { + return array(1.0, + "Sends static files via nginx X-Accel-Redirect header", + "fox", + true); + } + + function init($host) { + $this->host = $host; + + $host->add_hook($host::HOOK_SEND_LOCAL_FILE, $this); + } + + function hook_send_local_file($filename) { + + if (defined('NGINX_XACCEL_PREFIX') && NGINX_XACCEL_PREFIX) { + + $mimetype = mime_content_type($filename); + + // this is hardly ideal but 1) only media is cached in images/ and 2) seemingly only mp4 + // video files are detected as octet-stream by mime_content_type() + + if ($mimetype == "application/octet-stream") + $mimetype = "video/mp4"; + + header("Content-type: $mimetype"); + + $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT"; + header("Last-Modified: $stamp", true); + + header("X-Accel-Redirect: " . NGINX_XACCEL_PREFIX . "/" . $filename); + + return true; + } + } + + function api_version() { + return 2; + } + +} +?> |