我正在使用带有Ubuntu和Rails的现成Droplet。
我从git中拉了一下并托管了我的代码并修改了以下文件/etc/nginx/sites-enabled/default
server {
listen 80;
root /home/noise_application/noise/public;
server_name _;
index index.htm index.html;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
之后我试图重新启动Nginx我得到 502网关错误
日志
2014/11/26 07:56:47 [error] 670#0: *11 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, request$
2014/11/26 09:42:16 [error] 671#0: *36 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, request$
2014/11/26 09:45:44 [error] 6572#0: *5 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, request$
2014/11/26 09:55:52 [error] 6572#0: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 09:56:58 [error] 6572#0: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 09:58:30 [error] 6572#0: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 10:02:48 [error] 18374#0: *7 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 10:06:31 [error] 21484#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 122.167.75.29, server: _, request$
2014/11/26 10:08:04 [error] 21484#0: *5 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 10:10:47 [error] 21484#0: *8 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reques$
2014/11/26 10:14:07 [error] 21484#0: *11 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reque$
2014/11/26 10:17:42 [error] 21484#0: *14 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reque$
2014/11/26 10:22:08 [error] 21484#0: *17 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.167.75.29, server: _, reque$
2014/11/26 10:29:14 [error] 21484#0: *23 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.166.182.253, server: _, req$
2014/11/26 10:30:34 [error] 4385#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.166.182.253, server: _, reque$
2014/11/26 10:36:44 [error] 4385#0: *5 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.166.182.253, server: _, reque$
2014/11/26 10:39:10 [error] 4385#0: *9 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.166.182.253, server: _, reque$
2014/11/26 10:41:44 [error] 4385#0: *13 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.166.182.253, server: _, requ$
2014/11/26 10:43:17 [error] 4385#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 122.166.182.253, server: _, request: "GET / HTTP/1.$
2014/11/26 10:46:12 [notice] 12550#0: signal process started
2014/11/26 10:47:06 [error] 12553#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 122.166.182.253, server: _, request: "GET / HTTP/1$
2014/11/26 10:47:37 [emerg] 12561#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2014/11/26 10:47:37 [emerg] 12561#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2014/11/26 10:47:37 [emerg] 12561#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2014/11/26 10:47:37 [emerg] 12561#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2014/11/26 10:47:37 [emerg] 12561#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2014/11/26 10:47:37 [emerg] 12561#0: still could not bind()
2014/11/26 10:47:54 [notice] 12562#0: signal process started
答案 0 :(得分:1)
您的服务器部分看起来没问题,但您必须设置上游(在您的情况下为app_server):
upstream app_server {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {...}
/tmp/unicorn.sock是unicorn socket,必须使用unicorn配置定义(可能会有所不同)。