したいこと。
nginxとunicornとec2でRailsアプリをデプロイしたい。
参考したQiita
[user](/var/www/projects/***) $ sudo cat /etc/nginx/conf.d/***.conf
upstream unicorn_server { server unix:/var/www/projects/***/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; client_max_body_size 4G; server_name 54.65.226.96; keepalive_timeout 5; # Location of our static files root /var/www/projects/***/public; location ~ ^/assets/ { root /var/www/projects/***/public; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://unicorn_server; break; } } error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/projects/***/public; } }
[user](/var/www/projects/***) $ cat config/unicorn.conf.rb
# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/projects/***" $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # before starting processes 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 Process.kill "QUIT", File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end # after finishing processes after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
回答3件
あなたの回答
tips
プレビュー