Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I tried several times and on multiple occasions to try and fix the below code for nginx with unicorn, but it just isen't working. So now posting here in last report some of you more talented could see my mistake and others can benefit from it too.

Im using:

  • nginx
  • unicorn

The problem is

  • No 502 error shown ( I use cap deploy:web:disable task to write the maintenance.html )
  • If nginx is running but unicorn is not im also getting a 502 error page

The nginx config:

upstream unicorn {


        server unix:/srv/books/shared/tmp/unicorn.sock fail_timeout=0;

    }

    server {

        listen 80 deferred;
        server_name        books.*;

            client_max_body_size 4G;
            keepalive_timeout 10;
            server_tokens off;

            root /srv/books/public;

            location / {
                try_files /system/maintenance.html $uri/index.html $uri @unicorn;
            }

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

            location @unicorn {
                error_page 502 /system/maintenance.html;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://unicorn;
            }

        }
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Place the error_page directive under server rather than location.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.