Managing Database Files with Ruby on Rails - Web server configuration (Page 3 of 4 )
Of course, the front end web server must be properly configured to recognize and process the X-Sendfile header. Mongrel does not support X-Sendfile, as it assumes you will proxy to it from a server more capable of serving static content.
If you are using Lighttpd, it has X-Sendfile support built in. For Lighttpd/FastCGI, just enable the allow-x-send-file option in the server configuration:
If you are using Apache 2, things are a little more complicated (although not by much). You have to install the mod_xsendfile module* into Apache. There are two configuration flags, both accepting on/off values, which can then be used to control X-Sendfile behavior:
XSendFile Determines whether the X-Sendfile header is processed at all.
XsendFileAllowAbove Determines whether that header can send files above the path of the request. It defaults to off for security reasons.
Both of these configuration options can be used in any configuration context, down to the .htaccess file (per-directory). Best practice dictates that you should only specify XSendFile on in the narrowest possible context. Having X-Sendfile unnecessarily enabled is a security risk, as it allows a server application to send any file that the web server can access to the client.
To my knowledge, there is no way to use X-Sendfile on Apache 1.3 at this time.
Serving Static Files
One advantage of filesystem storage is that as long as the file data doesn't need to be protected with access control or otherwise acted upon dynamically, you can leverage your static web servers to serve that data. By exporting the storage path via NFS (or a caching filesystem such as AFS to conserve bandwidth), you can share the application's files with the static servers on your content distribution network. This completely removes the load from the application servers and provides a more scalable solution.