3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Django Rest Framework + nginx で 「connect() to /hoge.sock failed (13: Permission denied)」が発生した時の対処法

Posted at

発生事象

Amazon EC2 上のUbuntuでDjango Rest Frameworkのデプロイ作業を行った際、
アクセス時に以下のエラーが発生してしまった。

image-100.png

nginxおよびgunicornの起動確認

$ systemctl status nginx
# 以下のような記述があれば問題なし
Active: active (running) since Sat 2022-07-02 10:13:05 UTC; 21min ago

$ systemctl status gunicorn
# 確認点は同上

nginxのログ確認

$ tail /var/log/nginx/error.log
※一部改行

/var/log/nginx/error.log
2022/07/02 06:20:03 [crit] 6037#6037: 
*368 connect() to unix:/home/ubuntu/hoge/hoge.sock failed (13: Permission denied) while connecting to upstream, 
client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", 
upstream: "http://unix:/home/ubuntu/hoge/hoge.sock:/", host: "35.79.89.205:80"

Permission denied ということなので、
/etc/nginx/nginx.conf でnginx側の実行ユーザーをroot(or DRFの所有者)に変更する。

/etc/nginx/nginx.conf
user www-data;

/etc/nginx/nginx.conf
user root;

修正後、$ sudo systemctl restart nginxでnginxを再起動すると正しく表示された。

3
2
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?