| |   |
| 34 | 34 | ### Debian / Ubuntu Linux |
| 35 | 35 | |
| 36 | 36 | $ sudo apt-get install nginx |
| |
|
| 38 | 38 | ### Gentoo Linux |
| 39 | 39 | |
| 40 | 40 | $ emerge www-servers/nginx |
| … | … | |
| 46 | 46 | and /opt/local/etc/nginx/nginx.conf on Mac OS X. |
| 47 | 47 | |
| 48 | 48 | ### /etc/nginx/nginx.conf |
| |
|
| 50 | 50 | user <name> <group>; |
| 51 | 51 | worker_processes 4; |
| 52 | 52 | pid /var/run/nginx.pid; |
| |
|
| 54 | 54 | events { |
| 55 | 55 | worker_connections 8192; |
| 56 | 56 | use epoll; |
| 57 | 57 | } |
| |
|
| 59 | 59 | http { |
| 60 | 60 | |
| 61 | 61 | include /etc/nginx/mime.types; |
| … | … | |
| 83 | 83 | server 127.0.0.1:4000; |
| 84 | 84 | server 127.0.0.1:4001; |
| 85 | 85 | } |
| |
|
| 87 | 87 | server { |
| 88 | 88 | listen 80; |
| |
|
| 90 | 90 | root /path/to/merb/app/current/public; |
| |
|
| 92 | 92 | access_log /path/to/merb/app/shared/log/access.log main; |
| 93 | 93 | access_log /path/to/merb/app/shared/log/error.log notice; |
| |
|
| 95 | 95 | location / { |
| |
|
| 97 | 97 | proxy_set_header X-Real-IP $remote_addr; |
| 98 | 98 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 99 | 99 | proxy_set_header Host $http_host; |
| |
|
| 101 | 101 | proxy_redirect false; |
| 102 | 102 | proxy_max_temp_file_size 0; |
| |
|
| 104 | 104 | if (-f $request_filename) { |
| 105 | 105 | break; |
| 106 | 106 | } |
| |
|
| 108 | 108 | if (-f $request_filename.html) { |
| 109 | 109 | rewrite (.*) $1.html break; |
| 110 | 110 | } |
| |
|
| 112 | 112 | if (!-f $request_filename) { |
| 113 | 113 | proxy_pass http://merb; |
| 114 | 114 | break; |
| 115 | 115 | } |
| |
|
| 117 | 117 | } # location |
| |
|
| 119 | 119 | } # server |
| 120 | 120 | |
| 121 | 121 | } # http |
| … | … | |
| 124 | 124 | ## Capistrano Task |
| 125 | 125 | |
| 126 | 126 | set :application, "app" |
| |
|
| 128 | 128 | set :scm, :git |
| 129 | 129 | set :repository, "git://github.com/user/repo.git" |
| 130 | 130 | set :deploy_to, "/path/to/merb/app" |
| |
|
| 132 | 132 | set :monit_group, "app" |
| 133 | 133 | set :merb_env, "production" |
| |
|
| 135 | 135 | role :app, "ip.of.your.server" |
| 136 | 136 | role :web, "ip.of.your.server" |
| 137 | 137 | role :db, "ip.of.your.server" |
| |
|
| 139 | 139 | ssh_options[:paranoid] = false |
| |
|
| 141 | 141 | namespace :deploy do |
| 142 | 142 | [:start, :stop, :restart].each do |action| |
| 143 | 143 | task action, :roles => :app do |
| 144 | 144 | sudo "/usr/sbin/monit #{action.to_s} all -g merb_#{monit_group}" |
| 145 | 145 | end |
| 146 | 146 | end |
| |
|
| 148 | 148 | task :migrate, :roles => :db do |
| 149 | 149 | run "cd #{release_path}; rake MERB_ENV=#{merb_env} db:migrate:up" |
| 150 | 150 | end |
| |
|
| 152 | 152 | task :spinner, :roles => :app do |
| 153 | 153 | start |
| 154 | 154 | end |
| … | … | |
| 176 | 176 | |
| 177 | 177 | check process merb_app_master |
| 178 | 178 | with pidfile /var/log/engineyard/app/app-production-merb.main.pid |
| start program = "/engineyard/bin/monit_merb_mpc app start_master -c2 -n4000" |
| stop program = "/engineyard/bin/monit_merb_mpc app stop_master" |
| #if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| start program = "/engineyard/bin/monit_merb_mpc app start_master -c2 -n4000" |
| stop program = "/engineyard/bin/monit_merb_mpc app stop_master" |
| if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| 182 | 182 | group merb_app |
| |
|
| 184 | 184 | # Worker configuration (one for each worker port required) |
| 185 | 185 | check process merb_app_4000 |
| 186 | 186 | with pidfile /var/log/engineyard/app/app-production-merb.4000.pid |
| start program = "/engineyard/bin/monit_merb_mpc app register_worker 4000" |
| stop program = "/engineyard/bin/monit_merb_mpc app restart_worker 4000" |
| if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| start program = "/engineyard/bin/monit_merb_mpc app register_worker 4000" |
| stop program = "/engineyard/bin/monit_merb_mpc app restart_worker 4000" |
| if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| 190 | 190 | group merb_app |
| |
|
| 192 | 192 | check process merb_app_4001 |
| 193 | 193 | with pidfile /var/log/engineyard/app/app-production-merb.4001.pid |
| start program = "/engineyard/bin/monit_merb_mpc app register_worker 4001" |
| stop program = "/engineyard/bin/monit_merb_mpc app restart_worker 4001" |
| if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| start program = "/engineyard/bin/monit_merb_mpc app register_worker 4001" |
| stop program = "/engineyard/bin/monit_merb_mpc app restart_worker 4001" |
| if totalmem is greater than 80.0 MB for 2 cycles then restart # eating up memory? |
| 197 | 197 | group merb_app |
| |
|
| 199 | 199 | |
| 200 | 200 | [http://wiki.codemongers.com/Main]: http://wiki.codemongers.com/Main |
| 201 | 201 | [Igor Sysoev]: http://sysoev.ru/en/ |