Rails App with Nginx and Unicorn OK in Development but wont in in Production

June 3, 2015 554 views
Nginx Ruby on Rails CentOS

I setup my server with the help of "How To Deploy Rails Apps Using Unicorn & Nginx on CentOS 6.5" everything is great if I run if I start Unicorn in development but I have a lot of issues if I try to start in production.

I cant get unicorn to start at all if I don't use the absolute "listen" path in my unicorn.rb.
If I do use the absolute path unicorn will start as well as Nginx but when I go to the site I just get the Nginx "502 Bad Gateway" error page.

CURRENT UNICORN.rb working in Development
working_directory "/var/www/YourAppName"
pid "/var/www/YourAppName/pids/unicorn.pid"
listen "/tmp/unicorn.YourAppName.sock"

stderrpath "/var/www/YourAppName/log/unicornerr.log"
path "/dev/null"

worker_processes 2
timeout 30

CURRENT nginx default.conf working in Development
upstream YourAppName {
server unix:/tmp/unicorn.YourAppName.sock fail_timeout=0;

server {

listen 80;
server_name localhost;

root /root/YourAppName/public;

try_files $uri/index.html $uri @YourAppName;

location @YourAppName {
proxysetheader X-Forwarded-For $proxyaddxforwardedfor;
proxysetheader Host $httphost;
redirect off;
proxy_pass http://YourAppName;

errorpage 500 502 503 504 /500.html;
maxbodysize 4G;
keepalive_timeout 10;

Be the first one to answer this question.