LoginSignup
30
30

More than 5 years have passed since last update.

Unicorn x Nginx x AWS で、*11 connect() to unix:/home/ec2-user/app/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream のエラーの回避方法

Last updated at Posted at 2015-01-07

ブラウザからNginx経由でUnicornに接続しようとした際に、502 Bad Gatewayが返却されてあれれってなったので調べました。

nginxのエラーログ

/var/log/nginx/app_error.log
*11 connect() to unix:/home/ec2-user/app/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream

どうもパーミッションがないとのことで、nginxを実行しているユーザを調べた所、

[ec2-user@ip-xxx.xxxx.xxx.xxx]$ ps aux | grep nginx
root      2089  0.0  0.0 109476  2124 ?        Ss   02:05   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 2091  0.0  0.0 109888  3248 ?        S    02:05   0:00 nginx: worker process

こんな感じでデフォルトだとnginxになっちゃうみたいですね。
以下の設定ファイルを書き換えて実行ユーザをec2-user(もしくはアプリケーションの実行ユーザ)に変更してあげれば解決できます。

/etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

#user  nginx;
user  ec2-user;
worker_processes  1;
30
30
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
30
30