Skip to content

Instantly share code, notes, and snippets.

@letsspeak
Created October 30, 2012 17:41
Show Gist options
  • Save letsspeak/3981772 to your computer and use it in GitHub Desktop.
Save letsspeak/3981772 to your computer and use it in GitHub Desktop.
Redmine on unicorn on nginx with mysql, my configuration files.
# Default setup is given for MySQL with ruby1.8. If you're running Redmine
# with MySQL and ruby1.9, replace the adapter name with `mysql2`.
# Examples for PostgreSQL and SQLite3 can be found at the end.
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: ******
encoding: utf8
development:
adapter: mysql2
database: redmine_development
host: localhost
username: redmine
password: ******
encoding: utf8
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: redmine_test
host: localhost
username: root
password:
encoding: utf8
test_pgsql:
adapter: postgresql
database: redmine_test
host: localhost
username: postgres
password: "postgres"
test_sqlite3:
adapter: sqlite3
database: db/test.sqlite3
#######################################################################
#
# This is the main Nginx configuration file.
#
# More information about the configuration options is available on
# * the English wiki - http://wiki.nginx.org/Main
# * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################
#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
# http://wiki.nginx.org/NginxHttpMainModule
#
#----------------------------------------------------------------------
user nginx;
worker_processes 3;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
#----------------------------------------------------------------------
# Events Module
#
# http://wiki.nginx.org/NginxHttpEventsModule
#
#----------------------------------------------------------------------
events {
worker_connections 1024;
}
#----------------------------------------------------------------------
# HTTP Core Module
#
# http://wiki.nginx.org/NginxHttpCoreModule
#
#----------------------------------------------------------------------
http {
upstream charag{
server 127.0.0.1:5000;
}
upstream redmine{
server 127.0.0.1:5001;
}
server {
listen 80;
server_name test.charag.jp;
access_log /var/log/nginx_access.log;
error_log /var/log/nginx_error.log;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
location / {
root /home/www/rails/charag/public;
if (-f $request_filename){
break;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://charag;
proxy_redirect off;
}
}
server {
listen 80;
server_name redmine.charag.jp;
access_log /var/log/nginx_redmine_access.log;
error_log /var/log/nginx_redmine_error.log;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
auth_basic "Secret Area";
auth_basic_user_file "/home/www/rails/redmine/.htpasswd";
location / {
root /home/www/rails/redmine/public;
if (-f $request_filename){
break;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://redmine;
proxy_redirect off;
}
}
}
worker_processes 2
#working_directory /home/www/rails/charag
listen File.expand_path("tmp/unicorn.sock", ENV['RAILS_ROOT'])
pid File.expand_path("tmp/unicorn.pid", ENV['RAILS_ROOT'])
timeout 60
preload_app true # ダウンタイムをなくす
stdout_path File.expand_path("log/unicorn.stdout.log", ENV['RAILS_ROOT'])
stderr_path File.expand_path("log/unicorn.stderr.log", ENV['RAILS_ROOT'])
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
sleep 1
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
@mochadwi
Copy link

awesome!!! thank you very much :)

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