簡體   English   中英

nginx,unicorn和rails通過對等錯誤重置連接

[英]connection reset by peer error with nginx, unicorn and rails

這是我在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 -VI得到這個配置標志列表時:

--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的第一次傳遞,所以我有點遺漏了很多上下文...

如果您需要更多信息,請告訴我......

有幾件事要嘗試:

在您的nginx配置中,將上游服務器設置為使用localhost:<unicorn-port>而不是套接字。 例:

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

由於nginx是您的Web服務器,我將從您的unicorn.rb刪除listen 80, :tcp_nopush => true

首先,感謝大家的想法。 我想出來了,我正在完全吠叫錯誤的樹。 問題是獨角獸未能開始。 這是因為我們的一個助手是一個類,而不是一個模塊,而瘦和webrick允許這個,Unicorn有小貓。 我有一些其他瑣碎的事情,但一旦我能夠啟動獨角獸的事情工作得很好。 在這篇文章的時候,我沒有意識到我必須開始獨角獸 - 我的腦袋已經堅定了......好吧,你得到了照片。

再次,感謝答案和評論中的想法。 我非常感激。

鍵盤和椅子之間存在錯誤。 :P

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM