<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: X-Sendfile</title>
    <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>X-Sendfile</title>
      <description>&lt;p&gt;... or the hidden secrets of lighty.&lt;/p&gt;


	&lt;p&gt;X-Sendfile is one of the important, but mostly unknown features. Time to put the spot-light on it and see why you want to use it.&lt;/p&gt;
&lt;p&gt;X-Sendfile is a special header option you can set in any FastCGI backend to tell lighty to ignore the content of the response and replace it by the file that is specified in the X-Sendfile header.&lt;/p&gt;


	&lt;p&gt;Doesn&amp;#8217;t sound dramatic in the first place, but if you spin the idea on some use-cases you will see why this is a good idea:&lt;/p&gt;


	&lt;p&gt;&amp;#8220;you are using a application based authentication before you grant access to files on your server. As you don&amp;#8217;t want to allow to fetch the files by non-authed users you have to place them into folder which is not accessable from the document-root. In your application you are streaming the file (let&amp;#8217;s say 200Mb each) to the server which forwards it to the client.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;But wait: you are basicly sending a large static file. That&amp;#8217;s lighty&amp;#8217;s job. That&amp;#8217;s what it can do best.&lt;/p&gt;


	&lt;p&gt;X-Sendfile is exactly doing that. You tell lighty to send the static file as response. All the response headers from the backend are forwarded, just Content-Length is added.&lt;/p&gt;


	&lt;p&gt;As result your whole application will use alot less memory, will be several times faster and you spend less time in optimizing your application.&lt;/p&gt;


	&lt;p&gt;To use it you have to load mod_fastcgi and set the option &amp;#8220;allow-x-sendfile&amp;#8221; in the fastcgi.server configuration. By default X-Sendfile is disabled as it allows to send any file that the webserver has access too. In short: only use it in controled environments.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.lighttpd.net/documentation/fastcgi.html"&gt;mod_fastcgi docs&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://trac.lighttpd.net/trac/wiki/HowToFightDeepLinking"&gt;How to fight deep linking&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Sun, 02 Jul 2006 05:53:10 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4b8ae4e8-fddc-4092-a250-a97472f66b9d</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile</link>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/1740</trackback:ping>
    </item>
    <item>
      <title>"X-Sendfile" by Jan Kneschke</title>
      <description>Range, ETag, Compression ... is all added now in mod_proxy_core. See &lt;a href="http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support" rel="nofollow"&gt;http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support&lt;/a&gt;</description>
      <pubDate>Sat, 22 Jul 2006 10:01:52 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e2df5d20-bf52-4fbb-a93b-428264bf5d9b</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1822</link>
    </item>
    <item>
      <title>"X-Sendfile" by Silencer</title>
      <description>Very nice feature, but it's definitely need to be compatible with range requests for resumable downloads.</description>
      <pubDate>Fri, 14 Jul 2006 20:34:56 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b8ddec4e-cdd6-4f27-bc31-d832c87bbf74</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1756</link>
    </item>
    <item>
      <title>"X-Sendfile" by Scott</title>
      <description>I did check the mod_scgi source, and it must have forked before the sendfile feature was added, because it's not there at all. I tried adding it in, because mod_fastcgi and mod_scgi are very similar, and was nearly successful, but the differences are enough that in the one place that matters, I couldn't figure out how to process the header.</description>
      <pubDate>Sun, 02 Jul 2006 18:35:20 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5c03b6d8-4cd8-449c-8b6b-bb4a5758d7e2</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1744</link>
    </item>
    <item>
      <title>"X-Sendfile" by Scott</title>
      <description>The docs specify "allow-x-send-file". Is "allow-x-sendfile" the correct option?

I love the idea of this header and understood its advantages immediately. But I am testing lighttpd with SCGI, and neither option seems to work, even SCGI is supposed to be based on the FastCGI code. Here's my SCGI config:

scgi.server = ("/" =
    ((
        "socket"            = "/tmp/scgi.socket",
        "allow-x-send-file" = "enable",
        "allow-x-sendfile"  = "enable",
        "check-local"       = "disable"
    ))
)

Yes, I pass ALL requests to the SCGI app.

I send the following back to lighttpd:

BEGIN
X-Sendfile: /app/docroot/eki/FAQ.html
X-LIGHTTPD-send-file: /app/docroot/eki/FAQ.html
Content-Type: text/plain

Hello!
END

The X-Sendfile header is passed through to the browser. The X-LIGHTTPD-send-file header is eaten by lighttpd. But I don't get the FAQ.html file. I just get the "Hello!" in the body.
</description>
      <pubDate>Sun, 02 Jul 2006 12:19:08 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:58304aeb-1d77-4f19-8b6d-4b7370448d9a</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1743</link>
    </item>
    <item>
      <title>"X-Sendfile" by Andi</title>
      <description>Wow, this sounds really good. Is there a way to check if X-Sendfile is available from the fastcgi application? Eg. Is there some environment variable to check? Also does it handle partial requests?</description>
      <pubDate>Sun, 02 Jul 2006 10:07:33 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1bd63766-c4be-48b3-896f-78dc58eb5376</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1742</link>
    </item>
    <item>
      <title>"X-Sendfile" by yo</title>
      <description>a basic example would be helpfull. how to use it in an enviroment where you want to specify the files dynamicaly and you got more than one file? just curious because the the php example on the wiki looks so static</description>
      <pubDate>Sun, 02 Jul 2006 06:22:32 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b297e6a5-f9c3-4c73-869e-dbb0af7f942f</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/02/x-sendfile#comment-1741</link>
    </item>
  </channel>
</rss>
