unepwcmc/SAPI — pull request #169 by simaob (2014-01-13 16:10:13+00:00)
Title: Hotfix  0.4.2

This Pull Request enables the use of **nginx** to serve large files, avoiding the memory leak issues of **Rails**' **send_file** method. This is done by enabling this config options in both the staging and production environments, under **config/environments/[staging|produciton].rb**.

This Pull Request also updates the **Rails** controllers to pass to send_file the real path of each file, instead of a path that could have symlinks in it. This is to avoid a 404 error from **ngingx**, which uses the full path to the folder that is shared between the multiple versions of the app that are deployed each time. (NB: The files to be downloaded are under this shared folder, so that they do not need to be regenerated each time we deploy).

For information sake here is the configuration used in **nginx**:

passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /home/rails/sapi/shared/public/downloads/=/downloads/;
passenger_pass_header X-Accel-Redirect;

location ~ ^/downloads/(.*)$ {
alias /home/rails/sapi/shared/public/downloads/$1;
internal;
}

As seen here: https://gist.github.com/ozgun/4547357