Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

unicorn + nginx setup + ssl

View unicorn.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
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;
}
Owner

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

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!

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.