3

I deployed a rails 4 application in OpsWorks (Ubuntu 14.04, nginx and unicorn), when I open the homepage I'm getting a 502 Bad Gateway error. In nginx/error.log I can see this error:

2015/01/25 06:19:42 [error] 3652#0: *1 connect() to unix:/srv/www/app/shared/sockets/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: IP, server: app$

For more information here you can see my nginx.conf:

user www-data;
worker_processes  10;

error_log  /var/log/nginx/error.log;
pid        /run/nginx.pid;

events {
  worker_connections  1024;
}

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


  access_log    /var/log/nginx/access.log;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_timeout  65;

  gzip  on;
  gzip_static  on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_types application/x-javascript application/xhtml+xml application/xml application/xml+rss text/css text/javascript text/plain text/xml;
  gzip_vary on;
  gzip_disable "MSIE [1-6].(?!.*SV1)";

  client_max_body_size 4m;

  server_names_hash_bucket_size 64;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;

  upstream unicorn-app {
    server unix:/srv/www/app/shared/sockets/unicorn.sock fail_timeout=0;
  }

}

Updated:

I have added 777 permission for the shared and sockets folder, and also for the unicorn.sock as you can see here:

drwxrwxrwx 9 deploy www-data 4096 Jan 25 06:01 shared

drwxrwxrwx 2 deploy www-data 4096 Jan 25 05:12 sockets

-rwxrwxrwx 1 deploy www-data 0 Jan 25 05:12 unicorn.sock

But I still have the same problem:

2015/01/26 21:19:52 [error] 3652#0: *62 connect() to unix:/srv/www/app/shared/sockets/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: IP, server: app, request: "GET / HTTP/1.1", upstream: "http://unix:/srv/www/app/shared/sockets/unicorn.sock:/", host: "ec2-117.us-west-2.compute.amazonaws.com"
darkcode
  • 131
  • 1
  • 4
  • unicorn is not running, or the path to the socket is wrong. – AD7six Jan 25 '15 at 17:20
  • if I write ps aux | grep unicorn,here is the result: ubuntu 16092 0.0 0.0 10464 932 pts/0 S+ 17:29 0:00 grep --color=auto unicorn – darkcode Jan 25 '15 at 17:30
  • that eliminates one cause - how about the other? – AD7six Jan 25 '15 at 17:31
  • when I try to enter in the /srv/www/app/shared folder I get "Permission denied" error, I can change the permissions for this folder, but would be good? The shared folder would be a correct location for the unicorn.sock? – darkcode Jan 25 '15 at 17:41
  • @darkcode, did you ever get this resolved? I am struggling with the exact same issue. Thanks! – readyornot May 06 '16 at 22:23

1 Answers1

1

Make sure /srv/www/app/shared/sockets/unicorn.sock has correct rights for the user nginx's worker processes are running with (www-data in your case).

Xavier Lucas
  • 12,815
  • 2
  • 44
  • 50