Skip to content

Instantly share code, notes, and snippets.

@samgranieri
Created March 1, 2012 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samgranieri/1953436 to your computer and use it in GitHub Desktop.
Save samgranieri/1953436 to your computer and use it in GitHub Desktop.
Wildcard .dev dns settings on osx
# create a new file at /var/named/dev.zone
$TTL 60
$ORIGIN dev.
@ 1D IN SOA localhost. root.dev. (46 3H 15M 1W 1D)
1D IN NS localhost.
1D IN A 127.0.0.1
*.dev. 60 IN A 127.0.0.1
# Add this to /etc/named.conf
zone "dev" IN {
type master;
file "dev.zone";
allow-update { none; };
};
upstream yoursite_dev {
server unix://Users/you/Sites/yoursite/tmp/sockets/unicorn.sock;
}
server {
client_max_body_size 100M;
listen 80;
server_name www.yoursite.dev;
root /Users/you/Sites/yoursite/public;
access_log /dev/null ;
error_log /dev/null ;
# access_log /Users/you/Sites/yoursite/log/nginx_access.log;
# error_log /Users/you/Sites/yoursite/log/nginx_error.log;
location /{
try_files /system/maintenance.html $uri $uri/index.html $uri.html @app;
if ( -f $document_root/system/maintenance.html) {
return 503;
}
}
location @app{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://yoursite_dev;
}
recursive_error_pages on;
error_page 500 502 504 /500.html;
error_page 503 @maintenance;
location @maintenance {
error_page 405 = /system/maintenance.html;
if (-f $request_filename) {
break;
}
rewrite ^ /system/maintenance.html break;
}
location = /500.html {
root /Users/you/Sites/yoursite/public;
}
location = /502.html {
root /Users/you/Sites/yoursite/public;
}
# location = ^/(assets)/ {
#root /Users/you/Sites/yoursite/public;
#expires max;
#gzip_static on;
#add_header Cache-Control public;
##add_header Last-Modified "";
##add_header ETag "";
# }
}
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! APP_ROOT
rescue LoadError
raise "RVM ruby lib is currently unavailable."
end
end
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
worker_processes 2
working_directory APP_ROOT
preload_app true
timeout 30
listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64
pid APP_ROOT + "/tmp/pids/unicorn.pid"
stderr_path APP_ROOT + "/log/unicorn.stderr.log"
stdout_path APP_ROOT + "/log/unicorn.stdout.log"
before_fork do |server, worker|
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin'
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
puts "Old master alerady dead"
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
system("echo #{Process.pid} > #{child_pid}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment