-
Notifications
You must be signed in to change notification settings - Fork 3
Deployment
We are using nginx as our webserver in conjunction with (phusion passenger)[https://www.phusionpassenger.com/] to serve Rails applications.
This application can serve very large CSV files, which when done with Ruby on Rails can cause memory leakage. Because of this we have decided to serve these files via nginx.
This required adding the following to the configuration of the site-available for the app:
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;
}
And enabling the following option in both the staging and production environments in the app.
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
Gems are packaged, following this article:
http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/
CORS is used (for now) in the Checklist, which enables it to be deployed separately from the API backend.
For now we use the rack-cors middleware for the development environment:
http://blog.carbonfive.com/2012/02/27/supporting-cross-domain-ajax-in-rails-using-jsonp-and-cors/
Staging and production environments have the appropriate headers defined in Apache config:
<VirtualHost *:80>
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
Header set Access-Control-Allow-Headers "X-Requested-With, X-Prototype-Version"
Header set Access-Control-Max-Age 1728000
...
Nginx:
server {
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Methods' "GET, POST, PUT, DELETE, OPTIONS";
add_header 'Access-Control-Allow-Headers' "X-Requested-With, X-Prototype-Version";
add_header 'Access-Control-Max-Age' 1728000;
....
- start redis redis-server
- start sidekiq bundle exec sidekiq
- create new download job curl --data "output_layout=alphabetical&level_of_listing=0&show_synonyms=1&show_english=1&show_spanish=1&show_french=1&scientific_name=pediocactus&page=0&per_page=20&locale=en&download[format]=pdf&download[doc_type]=index" http://localhost:3000/downloads
response: {"downloads":[{"id":2,"doc_type":"index","format":"pdf","status":"working","created_at":"2012-10-30T11:44:21Z","updated_at":"2012-10-30T11:44:21Z"}]} 3. get status of job curl http://localhost:3000/downloads/2
response: {"status":"completed"}
- which directories need to be set up for the downloads / uploads to work
- which workers need to by running and what for
- which config is needed for the Checklist to connect to the right backend