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"