LoginSignup
katsumasa0514
@katsumasa0514 (ASAP k)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

djangoアプリをnginxとgunicornを使いデプロイしたいが、エラー「502 Bad Gateway」が出て進めません。

参考サイトを元にAWSのEC2にdjangoアプリをデプロイしています。
今回nginxとgunicornを使いデプロイしようとしており、参考サイトの最後でブラウザに接続したのですが、「502 Bad Gateway」が出て上手くいかず困っています。
環境は参考サイトとほぼ同じで、DBにMYSQLを使っているだけの違いです。

参考サイト

nginxのエラーログ

2021/04/10 01:56:45 [emerg] 44550#44550: bind() to 0.0.0.0:80 failed (98: Address already in use)
2021/04/10 01:56:45 [emerg] 44550#44550: bind() to [::]:80 failed (98: Address already in use)
2021/04/10 01:56:45 [emerg] 44550#44550: still could not bind()
2021/04/10 02:00:59 [crit] 44395#44395: *4 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:01:13 [crit] 44395#44395: *4 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:01:14 [crit] 44395#44395: *4 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:02:43 [crit] 44395#44395: *8 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:02:45 [crit] 44395#44395: *8 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:02:48 [crit] 44395#44395: *8 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:02:54 [crit] 44395#44395: *8 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 114.151.165.1, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0"
2021/04/10 02:06:57 [crit] 44395#44395: *13 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 46.191.234.21, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0:80"
2021/04/10 02:08:20 [crit] 44395#44395: *15 connect() to unix:/home/ubuntu/movieist/container/django_app/django_app.sock failed (2: No such file or directory) while connecting to upstream, client: 128.199.228.238, server: 54.168.166.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/movieist/container/django_app/django_app.sock:/", host: "54.168.166.0:80"

エラーログについて調べましたが理解ができず行き詰まってしまいました。

至らない点が多々あるかと思いますが、よろしくお願いします。

0

1Answer

2021/04/10 01:56:45 [emerg] 44550#44550: bind() to 0.0.0.0:80 failed (98: Address already in use)

これは、 nginx が 80 番ポートに bind しようとしたときに、すでに 80 番ポートが他のプロセスなどで使われていた、というものです。

sudo lsof -i :80

などを実行して、80 番ポートを使っているプロセスを特定し、そのプロセスを終了させてから、再度デプロイしてみてください。

1

Comments

  1. @katsumasa0514

    Questioner
    前回の回答に引き続きありがとうございます!
    一からやり直して、デプロイできました!
    yoshiさんのご協力があっての成果です。
    本当にありがとうございました

Your answer might help someone💌