Skip to content

Instantly share code, notes, and snippets.

@ingoclaro
Last active December 15, 2015 08:39
Show Gist options
  • Save ingoclaro/5232299 to your computer and use it in GitHub Desktop.
Save ingoclaro/5232299 to your computer and use it in GitHub Desktop.
nginx and passenger configuration for multiple apps on the same vhost
config.action_controller.page_cache_directory = "#{Rails.root}/public/cache"
namespace :deploy do
# for passenger
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end
server {
listen 80;
server_name app.com;
root /var/www;
access_log /var/log/nginx/app.com_access.log;
error_log /var/log/nginx/app.com_error.log error;
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
return 405;
}
location ~ "^/.*/assets/(.*/)*.*-[0-9a-f]{32}.*" {
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
location = /favicon.ico {
expires 1w;
add_header Cache-Control public;
}
location ~ "^/app1(.*)" {
# you should symlinc /var/www/app1 to your rails public folder
root /var/www/app1;
gzip_static on; # to serve pre-gzipped version
# cached pages are under the public/cached directory
try_files /system/maintenance.html /cache/$1/index.html /cache/$1.html $1 @app1;
}
location @app1 {
passenger_enabled on;
passenger_base_uri /app1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment