这是我在 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,所以我仍然缺少很多上下文......
如果您需要更多信息,请告诉我...