獨角獸 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 的錯誤方法
当我试图通过浏览器经由Nginx连接到Unicorn时,收到502 Bad Gateway错误响应,我对此进行了调查。
nginx的错误日志
*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(或应用程序的执行用户),问题就可以解决了。
# 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;