我正处于从Passenger迁移到Unicorn的过程中,我在配置工作方面遇到了一些麻烦。
我看到的问题是我的所有连接似乎都超时,但stderr.log和stdout.log文件中没有记录错误。我已经验证我的端口是在AWS sec组上打开的。
这就是我在stderr.log中看到的内容
I, [2012-08-21T19:26:36.462776 #7989] INFO -- : unlinking existing socket=/data/test/staging/current/tmp/sockets/unicorn.sock
I, [2012-08-21T19:26:36.463048 #7989] INFO -- : listening on addr=/data/test/staging/current/tmp/sockets/unicorn.sock fd=3
I, [2012-08-21T19:26:36.463466 #7989] INFO -- : Refreshing Gem list
I, [2012-08-21T19:27:50.293399 #7989] INFO -- : master process ready
I, [2012-08-21T19:27:50.687491 #8083] INFO -- : worker=0 ready
I, [2012-08-21T19:27:50.751790 #8086] INFO -- : worker=1 ready
cache: [GET /] miss
这是我目前的配置结构:
nginx.conf
user www-data;
worker_processes 2;
daemon off;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
server_names_hash_bucket_size 64;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
unicorn.rb
worker_processes 2
working_directory "/data/test/staging/current"
preload_app true
timeout 30
listen "/data/test/staging/current/tmp/sockets/unicorn.sock", :backlog => 64
pid "/data/test/staging/current/tmp/pids/unicorn.pid"
# Set the path of the log files inside the log folder of the testapp
stderr_path "/data/test/staging/current/log/unicorn.stderr.log"
stdout_path "/data/test/staging/current/log/unicorn.stdout.log"
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
000-默认
upstream test_server {
#This is the socket we configured in unicorn.rb
server unix:/data/test/staging/current/tmp/sockets/unicorn.sock »
fail_timeout=0;
}
server {
listen 80;
client_max_body_size 4G;
server_name http://ec2-23-22-53-139.compute-1.amazonaws.com;
keepalive_timeout 5;
# Location of our static files
root /data/test/staging/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://test_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /data/test/staging/current/public;
}
}
答案 0 :(得分:1)
我首先将Socket和Pid文件放在共享目录中。 EG,
/data/test/staging/shared/sockets
/data/test/staging/shared/pids
这将有助于部署应用程序并将“当前文件夹”更改为下一个版本(假设您使用capistrano进行部署)。