首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx + Unicorn配置问题

Nginx + Unicorn配置问题
EN

Stack Overflow用户
提问于 2012-08-21 19:53:19
回答 1查看 3.5K关注 0票数 1

我正在从乘客迁移到Unicorn的过程中,我的配置工作有点困难。

我看到的问题是,我的所有连接似乎都超时了,但是在stderr.log和stdout.log文件中没有记录错误。我已经验证了我的端口在AWS sec组上是开放的。

这就是我在我的stderr.log中看到的

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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-默认

代码语言:javascript
复制
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;
}
}
EN

回答 1

Stack Overflow用户

发布于 2012-11-06 06:22:58

首先,我将把套接字和Pid文件放在共享目录中。例如,

代码语言:javascript
复制
/data/test/staging/shared/sockets
/data/test/staging/shared/pids

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12062058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档