它是我第一次設置nginx和獨角獸。在上游「應用程序」中找不到主機nginx不在應用程序中停留在歡迎頁上
我的capistrano部署已經完成,一切都成功了。
here is my unicorn.rb
#app_dir = File.expand_path('../../', __FILE__)
#shared_dir = File.expand_path('../../../shared/', __FILE__)
preload_app true
worker_processes 4
timeout 30
working_directory "home/deploy/appname"
shared_dir = "home/deploy/appname/shared"
# Set up socket location
# by default unicorn listens on 8080
listen "#{shared_dir}/tmp/sockets/unicorn.sock", :backlog => 64
# Logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set master PID location
pid "#{shared_dir}/tmp/pids/unicorn.pid"
#must set preload app true to use before/after fork
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
#before forking, this is suppose to kill the master process that belongs to the oldbin
#enables 0 downtime to deploy
old_pid = "#{shared_dir}/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
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
# before_exec do |server|
# ENV['BUNDLE_GEMFILE'] = "#{app_dir}/Gemfile"
# end
處/etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我的默認文件我的nginx的conf的/ etc/nginx的/ /默認
upstream app_server {
#path to unicorn sock file, as defined previously
server unix:/home/deploy/appname/shared/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
root /home/deploy/appname;
try_files $uri/index.html $uri @app;
#click tracking
access_log /var/log/nginx/appname_access.log combined;
error_log /var/log/nginx/appname_error.log;
location @app {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
當我啓用的站點 - 這
[email protected]:~$ sudo nginx -s reload
nginx: [emerg] host not found in upstream "app" in /etc/nginx/sites-enabled/default:46
當我進入
/shared/tmp/sockets
我沒有在那裏的文件。我認爲我不應該手動創建它。我正在使用capistrano 3.我想生成這個文件嗎?
我在deploy.rb
象徵性的文件和目錄
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{tmp/pids tmp/cache tmp/sockets log bin vendor/bundle public/system}
#just pointing to our unicorn.rb
set :unicorn_config_path, "config/unicorn.rb"
#capistrano tasks and processes
after "deploy", "deploy:cleanup"
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'unicorn:restart'
end
end
after :finishing, "deploy:cleanup"
end
我把我的帽子文件,在這裏,因爲我發現在我的帽子上麒麟重新啓動的日誌使用
require 'capistrano3/unicorn' #in capfile
生產部署日誌。我不確定這是否有幫助。
我確保working_directory匹配默認nginx頁面中的根目錄。 我確保在獨角獸中的偵聽與默認頁面中的上游應用程序服務器unix相匹配。 我確保nginx.conf文件包含啓用網站的默認配置nginx頁面。