Anthony
Anthony

Reputation: 21

Cannot get nginx/unicorn working again. nginx - connect() failed (111: Connection refused) while connecting to upstream

I'm running Nginx /unicorn I'm getting errors "failed (111: Connection refused) while connecting to upstream" from nginx. It was working for a while but after digital ocean support did a reboot of my droplet (another problem) I cannot get it working again. I've looked at memory, rotated the logs, bounced the sever, nginx and unicorn. I've tried changing the socket location, name and permissions, and after all that I even tried throwing holy water and screaming at my terminal to exercise the demons away. :-) It seems I've tried just about everything DO support, google and stackoverflow have to offer. I dont know if I'm overlooking something or I've tried so much that i've now messed something up. Here is all the configs, analysis, ect...

Nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
worker_rlimit_nofile 30000;

events { worker_connections 1024; }

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        proxy_connect_timeout 60;
        proxy_read_timeout 60;
        proxy_send_timeout 60;


        gzip on;
        gzip_disable "msie6";
        gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server {
        server 127.0.0.1:8080 fail_timeout=0;
        }

# FAIL upstream app_server {server unix:/home/puma/sockets/puma.sock fail_timeout=0; }
         # FAIL upstream app_server {server unix:/home/rails/tmp/sockets/unicorn.flossfish.sock fail_timeout=0; }
        include /etc/nginx/conf.d/*.conf;
       include /etc/nginx/sites-enabled/*;
}

===========================
nginx/sited-enabled/default
server {
        listen   80;
        root /home/rails/public;
        #server_name _;
        server_name localhost;
        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;
    }

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


}


============================
unicorn.conf


listen "127.0.0.1:8080"
# FAIL listen "/home/rails/tmp/sockets/unicorn.flossfish.sock"

worker_processes 4
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/logs/error.log"
stdout_path "/home/unicorn/logs/access.log"

timeout 30

----------------------------------------
netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      21572/unicorn.conf 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21546/nginx.conf


Grep nginx

ps -ef | grep nginx
root      9993  9242  0 Oct14 pts/2    00:00:00 tail -100f /var/log/nginx/error.log
root     21546     1  0 14:37 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
www-data 21549 21546  0 14:37 ?        00:00:00 nginx: worker process                   
www-data 21550 21546  0 14:37 ?        00:00:00 nginx: worker process                   
www-data 21551 21546  0 14:37 ?        00:00:00 nginx: worker process                   
www-data 21552 21546  0 14:37 ?        00:00:00 nginx: worker process


grep unicorn 
ps -ef | grep unicorn
root     20731  9242  0 13:52 pts/2    00:00:00 tail -f /home/unicorn/logs/error.log
root     21572     1  0 14:38 ?        00:00:00 unicorn master -D -c /home/unicorn/unicorn.conf -E production                                                                                               
rails    21575 21572  1 14:38 ?        00:00:04 unicorn worker[0] -D -c /home/unicorn/unicorn.conf -E production                                                                                            
rails    21578 21572  1 14:38 ?        00:00:04 unicorn worker[1] -D -c /home/unicorn/unicorn.conf -E production                                                                                            
rails    21580 21572  1 14:38 ?        00:00:04 unicorn worker[2] -D -c /home/unicorn/unicorn.conf -E production                                                                                            
rails    21583 21572  1 14:38 ?        00:00:04 unicorn worker[3] -D -c /home/unicorn/unicorn.conf -E production


-------------------------------------------------------

 lsof -i :
nginx   16954     root    6u  IPv4 131527      0t0  TCP *:http (LISTEN)
nginx   16957 www-data    6u  IPv4 131527      0t0  TCP *:http (LISTEN)
nginx   16958 www-data    6u  IPv4 131527      0t0  TCP *:http (LISTEN)
nginx   16959 www-data    6u  IPv4 131527      0t0  TCP *:http (LISTEN)
nginx   16959 www-data    9u  IPv4 132064      0t0  TCP 104.236.247.33:http->118.101.25.229:54644 (ESTABLISHED)
nginx   16959 www-data   10u  IPv4 132065      0t0  TCP 104.236.247.33:http->118.101.25.229:54645 (ESTABLISHED)
nginx   16959 www-data   14u  IPv4 132074      0t0  TCP 104.236.247.33:http->112.208.71.167.pldt.net:62601(ESTABLISHED)
nginx   16960 www-data    6u  IPv4 131527      0t0  TCP *:http (LISTEN)
ruby    16984     root   10u  IPv4 131638      0t0  TCP localhost:http-alt (LISTEN)
ruby    16987    rails   10u  IPv4 131638      0t0  TCP localhost:http-alt (LISTEN)
ruby    16990    rails   10u  IPv4 131638      0t0  TCP localhost:http-alt (LISTEN)
ruby    16993    rails   10u  IPv4 131638      0t0  TCP localhost:http-alt (LISTEN)
ruby    16996    rails   10u  IPv4 131638      0t0  TCP localhost:http-alt (LISTEN)

Thanks in advance for any help on this problem.

Upvotes: 1

Views: 1463

Answers (1)

Anthony
Anthony

Reputation: 21

Thanks Everyone. it turns out this was a rails/permission problem. I looked just about everywhere except in the unicorn access logs and thats where i discovered the problem. I think ultimately when the server was bounced I restarted the rails/unicorn processes and precompiled the rails assets under root user and it caused some folder permission issues at /tmp/cache/.... I set those permissions, chowed and viola everything stated working again! –

Upvotes: 1

Related Questions