lighty's life

lighty developer blog


... or the hidden secrets of lighty. 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. 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. Doesn'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: "you are using a application based authentication before you grant access to files on your server. As you don'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's say 200Mb each) to the server which forwards it to the client." But wait: you are basicly sending a large static file. That's lighty's job. That's what it can do best. 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. As result your whole application will use alot less memory, will be several times faster and you spend less time in optimizing your application. To use it you have to load mod_fastcgi and set the option "allow-x-sendfile" 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. * "mod_fastcgi docs":// * "How to fight deep linking"://

Please note that we won't accept comments for posts older than 3 months! Also please use our bug tracker to report bugs, and our irc channel #lighttpd@libera to chat.

« What I learned at the railsconf The New mod_proxy_core »