This question has been archived.

Problem with Nginx, Unicorn and Rails application ( 502 Bad Gateway )

March 18, 2015 4.5k views
Nginx Ruby on Rails Linux Basics Configuration Management


Recently I've created a DigitalOcean droplet using preinstalled package with Nginx, and Unicorn.

Here is mine /etc/nginx/conf.d/default.conf

upstream app {
    server unix:/var/sockets/unicorn.mypage.sock fail_timeout=0;

server {

    listen 80;

    # Application root, as defined previously
    root /home/rails/mypage/public;

    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control 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;


working_directory "/home/rails/mypage"

pid "/home/rails/mypage/pids/"

stderr_path "/home/rails/mypage/log/unicorn.log"
stdout_path "/home/rails/mypage/log/unicorn.log"

listen "/var/sockets/unicorn.mypage.sock", backlog: 1024

worker_processes 2

timeout 30

nginx and unicorn are running, I checked that using ps command

but when trying to access my page Ive got 502 Bad Gateway

nginx error log has line

2015/03/18 19:53:26 [error] 14319#0: *1 connect() to unix:/var/sockets/unicorn.mypage.sock failed (11: Resource temporarily unavailable) while connecting to upstream

What can be the problem?


1 comment
  • Hi, are you still having this issue with the current one-click install of Nginx and Unicorn?

Be the first one to answer this question.