I'm trying to deploy a rails app to azure using Nginx and Unicorn. I have been following this tutorial When I got to the end of the tutorial and launched the site I got a 502 bad gateway error. In my nginx error.log I get these two lines for each page load:
2015/05/10 19:04:37 [crit] 2784#0: *7 stat() "/var/www/offWhite/public/500.html" failed (13: Permission denied), client: 174.60.87.237, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.offWhite.sock:/", host: "offfwhite.cloudapp.net"
2015/05/10 19:04:37 [crit] 2784#0: *7 connect() to unix:/tmp/unicorn.offWhite.sock failed (13: Permission denied) while connecting to upstream, client: 174.60.87.237, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.offWhite.sock:/", host: "offfwhite.cloudapp.net"
My config/unicorn.rb
looks just like the one in the tutorial:
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/offWhite"
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/offWhite/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/offWhite/log/unicorn.log"
stdout_path "/var/www/offWhite/log/unicorn.log"
# Unicorn socket
listen "/tmp/unicorn.offWhite.sock"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
And so does my nginx default.conf:
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.offWhite.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
# Application root, as defined previously
root /var/www/offWhite/public;
try_files $uri/index.html $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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
From what I've found online, there are often issues with permissions. I don't want to get chmod happy though quite yet, if there are any other options.
Thank you, a lot
Alex
I'm not sure if this should have gone on server fault. If it should let me know and I'll take it down.
Edit:
This is what I get in my unicorn.log each time I start the server:
I, [2015-05-10T18:31:55.017694 #47698] INFO -- : reaped #<Process::Status: pid 47701 exit 0> worker=0
I, [2015-05-10T18:31:55.017868 #47698] INFO -- : reaped #<Process::Status: pid 47703 exit 0> worker=1
I, [2015-05-10T18:31:55.018017 #47698] INFO -- : master complete
I, [2015-05-10T18:32:25.839675 #2048] INFO -- : unlinking existing socket=/tmp/unicorn.offWhite.sock
I, [2015-05-10T18:32:25.840092 #2048] INFO -- : listening on addr=/tmp/unicorn.offWhite.sock fd=10
I, [2015-05-10T18:32:25.840290 #2048] INFO -- : worker=0 spawning...
I, [2015-05-10T18:32:25.841098 #2048] INFO -- : worker=1 spawning...
I, [2015-05-10T18:32:25.841860 #2048] INFO -- : master process ready
I, [2015-05-10T18:32:25.845775 #2053] INFO -- : worker=1 spawned pid=2053
I, [2015-05-10T18:32:25.846049 #2053] INFO -- : Refreshing Gem list
I, [2015-05-10T18:32:25.853470 #2051] INFO -- : worker=0 spawned pid=2051
I, [2015-05-10T18:32:25.853751 #2051] INFO -- : Refreshing Gem list
I, [2015-05-10T18:32:28.002957 #2051] INFO -- : worker=0 ready
I, [2015-05-10T18:32:28.020675 #2053] INFO -- : worker=1 ready
I'm answering my own question a couple months now after solving the problem, so I don't have the exact logs I used in my deduction.
Basically, there was an error in unicorn's log because I never declared the production database secret.