Using X-Sendfile in Rails with lighttpd
As a followup to my post on using x-sendfile, I sent some email to Jan, owner of lighttpd. He clued me into the mod_setenv module that allows me to write this in my lighttpd.conf:
setenv.add-environment = (
"ENABLE_X_SENDFILE" => "true"
)as well as the allow-x-send-file property for FastCGI and soon to be proxy-core configuration.
Now my Rails source code can look like this:
if request.env["ENABLE_X_SENDFILE"] == "true"
response.headers["X-Sendfile"] = filename_to_send
else
response.body = read_file(filename_to_send)
endThe configuration to enable x-sendfile is duplicated, but at least it’s in a single .conf file.