3
2

More than 5 years have passed since last update.

nginxでルーティングを間違えて502エラーが返ってきた時の対処

Last updated at Posted at 2015-12-09

ログを見ると以下のようなエラーが返ってきてました。

502 Bad Gateway Error Nginx connect() to unix:/tmp/unicorn.sock failed

環境

  • Ruby on Rails4.2.x
  • unicorn
  • nginx

解決

*.confファイルのunicorn.sockのパスの位置を確認しましょう。

upstream unicorn_server {
  server unix:/var/www/#{application}/current/tmp/unicorn.sock
  fail_timeout=0;
}

server {
  listen 80;
  server_name sever_name;

  keepalive_timeout 5;

  root /var/www/#{application}/current/public;
  access_log /var/log/nginx/#{application}_access.log;
  error_log /var/log/nginx/#{application}_error.log;

  error_page 500 502 503 504 /500.html;

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

  location @unicorn {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_pass http://unicorn_server;
  }

 # location ~ ^/assets/ {
 #   root /var/www/#{application}/current/public;
 # }

  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /var/www/#{application}/current/public;
  }
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2