2

my nginx configuration is as:

upstream app_server {
        server unix:/run/DigitalOceanOneClick/unicorn.sock fail_timeout=0;
    }

    server {
        listen   80;
        root /home/rails/rails_project/public;
        server_name example.com www.example.com;
        index index.htm index.html;

        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                        try_files $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_server;
                proxy_read_timeout 180;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
        }
    }  

And unicorn configuration file is as:

listen "unix:/run/DigitalOceanOneClick/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/rails_project"
pid "/run/DigitalOceanOneClick/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"  

I'm getting "504 Gateway Time-out" error frequently. I'm not getting any idea about the problem. Server OS is Ubuntu 14.04 with rails5.1.3, nginx and unicorn. Thank you.

codemilan
  • 1,072
  • 3
  • 12
  • 32
  • 1
    try adding `proxy_connect_timeout` also to your config and see if that helps. Keep it at 120 or so – Tarun Lalwani Sep 15 '17 at 20:32
  • no luck. Thank you @TarunLalwani – codemilan Sep 16 '17 at 17:41
  • 1
    See if these helps https://stackoverflow.com/questions/24970867/rails-deployment-with-nginx-and-unicorn-giving-504-gateway-timeout-error, you want to put your unicorn in debug mode and also run `journalctl -f -n10` and observe the log during 504, see if a unicorn worker is being killed. See the timeout and stack trace options also on https://devcenter.heroku.com/articles/rails-unicorn. Also another on you should consider https://stackoverflow.com/questions/561946/how-do-i-prevent-a-gateway-timeout-with-fastcgi-on-nginx – Tarun Lalwani Sep 17 '17 at 06:16
  • thank you alot @TarunLalwani. I somehow solved it, I didn't knew the exact solution, but I guess it was due to mix-max of env. variables, I did full clean up of nginx & unicorn configurations, stopped the related services, cleaned sock and pid files and finally got the app running. Thank you again. – codemilan Sep 18 '17 at 09:40
  • Glad its working for you :-) – Tarun Lalwani Sep 18 '17 at 09:42

0 Answers0