1

我正在从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/*;
}

独角兽.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;
}
}
4

1 回答 1

1

我首先将 Socket 和 Pid 文件放在共享目录中。例如,

/data/test/staging/shared/sockets
/data/test/staging/shared/pids

当应用程序被部署并且“当前文件夹”更改为下一个版本(假设您使用 capistrano 进行部署)时,这将有所帮助。

于 2012-11-06T06:22:58.090 回答