nginx,unicorn和rails通过对等错误重置连接

时间:2013-11-10 16:07:28

标签: ruby-on-rails nginx capistrano unicorn

这是我在nginx错误日志中看到的输出:

013/11/10 09:40:38 [error] 20439#0: *1021 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: <server ip>, server: , request: "GET / HTTP/1.0", upstream: "http:/some ip address:80/", host: "some id address"

这是nginx.conf文件内容:

user  www-user;
worker_processes  1;

#error_log  /var/log/nginx/error.log warn;
error_log  /srv/app.myserver.com/current/log/nginx-error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 30000;

events {
    worker_connections  10000;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;
    access_log  /srv/app.myserver.com/current/log/nginx-access.log main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/myserver.conf;
}

以下是/etc/nginx/conf.d/myserver.conf的内容:

upstream myserver {
  # This is the socket we configured in unicorn.rb
  server unix:/srv/app.myserver.com/current/tmp/myserver.sock
  fail_timeout=0;
}

server {
  listen 80 default deferred;
  #client_max_body_size 4G;
  server_name app.myserver.com;

  #keepalive_timeout 5;

  # Location of our static files
  root /srv/app.myserver.com/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @myserver;

  location @myserver {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://myserver;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

最后,这是我的config / unicorn.rb文件的内容,其中删除了注释以节省空间:

worker_processes 4

user "www-user", "www-user"


root = "/srv/app.myserver.com/current/"
working_directory root

# QUESTION HERE: should this be considered relative to working_directory or from filesystem root?
listen "/tmp/myserver.sock", :backlog => 64
listen 8080, :tcp_nopush => true
listen 80, :tcp_nopush => true

timeout 30

pid "/srv/app.myserver.com/current/tmp/pids/unicorn.pid"

我正在使用Capistrano进行部署,我确保tmp目录在那里,并且那里有一个myserver.sock文件。

最后,当我执行nginx -V时,我得到了这个配置标志列表:

--prefix=/etc/nginx 
--sbin-path=/usr/sbin/nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log 
--pid-path=/var/run/nginx.pid 
--lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/var/cache/nginx/client_temp 
--http-proxy-temp-path=/var/cache/nginx/proxy_temp 
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp 
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp 
--http-scgi-temp-path=/var/cache/nginx/scgi_temp 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_addition_module 
--with-http_sub_module 
--with-http_dav_module 
--with-http_flv_module 
--with-http_mp4_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_random_index_module 
--with-http_secure_link_module 
--with-http_stub_status_module 
--with-mail 
--with-mail_ssl_module 
--with-file-aio 
--with-ipv6 
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables'

我没有看到任何内容呼唤上游模块。这可能是我的问题吗?

这是我使用nginx和unicorn的第一次传递,所以我仍然缺少很多上下文......

如果您需要更多信息,请告诉我......

2 个答案:

答案 0 :(得分:1)

有几件事要尝试:

在您的nginx配置中,将您的上游服务器设置为使用localhost:<unicorn-port>而不是套接字。例如:

upstream myserver {
  server localhost:8080 fail_timeout=0;
}

由于nginx是您的网络服务器,因此我会从listen 80, :tcp_nopush => true中删除unicorn.rb

答案 1 :(得分:1)

首先,感谢大家的想法。我想出来了,我正在完全吠叫错误的树。问题是独角兽未能开始。这是因为我们的一个助手是一个类,而不是一个模块,而瘦和webrick允许这个,Unicorn有小猫。我有一些其他琐碎的事情,但一旦我能够启动独角兽的事情工作得很好。在这篇文章的时候,我没有意识到我必须开始独角兽 - 我的脑袋已经坚定了......好吧,你得到的照片。

再次感谢答案和评论中的想法。我非常感激。

键盘和主席之间存在错误。 :P