Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
unicorn + nginx setup + ssl
unicorn.rb
-----------------------------------
application = "jarvis"
remote_user = "vagrant"
env = ENV["RAILS_ENV"] || "development"
RAILS_ROOT = File.join("/home", remote_user, application)
worker_processes 8
timeout 30
preload_app true
working_directory RAILS_ROOT
listen File.join(RAILS_ROOT, "tmp/unicorn.sock"), :backlog => 64
pid_path = File.join(RAILS_ROOT, "tmp/pids/unicorn.pid")
pid pid_path
stderr_path File.join(RAILS_ROOT, "log/unicorn-err.log")
stdout_path File.join(RAILS_ROOT, "log/unicorn-err.log")
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
old_pid_path = "#{pid_path}.oldbin"
if File.exists?(old_pid_path) && server.pid != old_pid_path
begin
Process.kill("QUIT", File.read(old_pid_path).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
# worker processes http://devmull.net/articles/unicorn-resque-bluepill
# rails_env = ENV['RAILS_ENV'] || 'production'
# worker.user('app', 'app') if Process.euid == 0 && rails_env == 'production'
end
nginx
----------------------------------
upstream dev.jarvis.com {
server unix:/home/vagrant/jarvis/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 443 default;
ssl on;
ssl_certificate /home/vagrant/ssl/server.cer;
ssl_certificate_key /home/vagrant/ssl/server.key;
server_name dev.jarvis.com;
root /home/vagrant/jarvis/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_redirect off;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://dev.jarvis.com;
}
error_page 502 503 /maintenance.html;
error_page 500 504 /500.html;
keepalive_timeout 5;
}
@johnantoni

This comment has been minimized.

Show comment Hide comment
@johnantoni

johnantoni Aug 2, 2012

works like a dream, not built for deployments as i was just testing it out on my dev box but that wouldn't take long

Owner

johnantoni commented Aug 2, 2012

works like a dream, not built for deployments as i was just testing it out on my dev box but that wouldn't take long

@felipeclopes

This comment has been minimized.

Show comment Hide comment
@felipeclopes

felipeclopes May 8, 2013

Cool! Do you have your deployment version? I'm having headaches trying to make this ssl works with nginx + unicorn using rubber scripts. If you have your unicorn and nginx configs for me it would be great!

Tnx!

Cool! Do you have your deployment version? I'm having headaches trying to make this ssl works with nginx + unicorn using rubber scripts. If you have your unicorn and nginx configs for me it would be great!

Tnx!

@martinstreicher

This comment has been minimized.

Show comment Hide comment
@martinstreicher

martinstreicher Apr 25, 2014

I am looking for a Unicorn + nginx + http > https example.

I am looking for a Unicorn + nginx + http > https example.

@r00takaspin

This comment has been minimized.

Show comment Hide comment
@r00takaspin

r00takaspin Dec 23, 2014

Thank you!

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment