質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

uWSGI

uWSGIは、PythonでWebサービスを動かすアプリケーションサーバの一つです。WSGI(Web Server Gateway Interface)アプリケーションコンテナの一種で、WSGIに則ったDjangoやFlaskなどで動かすことができます。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

2027閲覧

nginxで(111: Connection refused)が出て、アクセスできない

karun

総合スコア18

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

uWSGI

uWSGIは、PythonでWebサービスを動かすアプリケーションサーバの一つです。WSGI(Web Server Gateway Interface)アプリケーションコンテナの一種で、WSGIに則ったDjangoやFlaskなどで動かすことができます。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2022/02/13 09:09

編集2022/02/13 13:47

Djangoの学習のため下記サイトを参考にしておりましたがタイトル通りの現象が起きつまづいております

①EC2の設定等は下記サイトを使用し作成
https://100webdesign.jp/services/web_knowhow/aws-site/web_knowhow-21160/
②EC2インスタンス作成以外こちらのサイトを参考
http://sounanda.jp/itskillup/?p=1193

今起きていること
イメージ説明

python manage.py runserver 0.0.0.0:8000
実行後は問題なくアクセスができ下記メッセージが出ておりました
②の14にあたります
It worked!
Congratulations on your first Django-powered page.

ですがNginxをインストール後イメージの通りのエラーが表示されております。
本来では
Welcome to nginx on Amazon Linux!
と出るようですが出ませんでした。
アクセスした際の/var/log/nginx/error.logは下記になります

2022/02/13 09:01:04 [error] 22939#22939: *40 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream:"http://127.0.0.1:8000/", host: "xxx.xxx.xxx.xxx" 2022/02/13 09:01:04 [error] 22939#22939: *40 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /nginx-logo.png HTTP/1.1", upstream: "http://127.0.0.1:8000/nginx-logo.png", host: "xxx.xxx.xxx.xxx", referrer: "http://xxx.xxx.xxx.xxx/" 2022/02/13 09:01:04 [error] 22939#22939: *39 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /poweredby.png HTTP/1.1", upstream: "http://127.0.0.1:8000/poweredby.png", host: "xxx.xxx.xxx.xxx", referrer: "http://xxx.xxx.xxx.xxx/"

②に関しては記載されていることを上から順に行っておりますので個人で何か加えたり調べた内容を追記した等はありません。
いろいろ調べてみましたが何が原因かわからないので投稿させていただきました

AWS関連の情報が足りていない等ございましたら随時追加いたしますのでご指摘いただければ追記致しますのでよろしくお願い致します。

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; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfileon; tcp_nopushon; tcp_nodelayon; keepalive_timeout 65; types_hash_max_size 4096; include/etc/nginx/mime.types; default_typeapplication/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; upstream app_server { server 127.0.0.1:8000 fail_timeout=0; } server { #listen 80; #listen [::]:80; #server_name _; #root /usr/share/nginx/html; #root /home/ec2-user/django/djangoApp; listen 80; server_name 18.177.35.81; client_max_body_size 4G; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2; # listen [::]:443 ssl http2; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers PROFILE=SYSTEM; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mike2mike4

2022/02/13 09:20

Djangoのことは知りませんがどこかの設定ファイルでhttp://127.0.0.1:8000/を指定してます
yu_1985

2022/02/13 11:14

nginxの設定を貼ってください。
karun

2022/02/13 13:48

nginx.confを追記致しました
yu_1985

2022/02/13 15:27

djangoのディレクトリをホームディレクトリ配下にしているせいでnginxユーザが拒否されてないですか? アプリをホームディレクトリに置くのはやめましょう。
TaichiYanagiya

2022/02/14 00:07

127.0.0.1:8000 に接続できないようです。 "ss -tln" で TCP 8000 番ポートが LISTEN しているか、IPアドレスが 127.0.0.1:8000 または 0.0.0.0:8000 となっているか確認ください。
karun

2022/02/14 17:02

TaichiYanagiyaさん コマンドした結果はいかになりました [ec2-user@ip-10-0-10-10 ~]$ ss -tln State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:111 0.0.0.0:* LISTEN 0 128 0.0.0.0:80 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 100 127.0.0.1:25 0.0.0.0:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 128 [::]:22 [::]:*
TaichiYanagiya

2022/02/14 23:22

LISTEN していないですね。python プログラムが起動していないです。
karun

2022/02/20 06:05

TaichiYanagiyaさん 返信が遅くなり申し訳ございません。 uwsgi --http :8000 --wsgi-file manage.py を行った後 ss -tln を行った結果は以下になります [ec2-user@ip-10-0-10-10 ~]$ ss -tln State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:111 0.0.0.0:* LISTEN 0 128 0.0.0.0:80 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 100 127.0.0.1:44025 0.0.0.0:* LISTEN 0 100 127.0.0.1:25 0.0.0.0:* LISTEN 0 100 0.0.0.0:8000 0.0.0.0:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 128 [::]:22 [::]:* その後アクセスし直したら「Internal Server Error」とだけでました その後のエラーログは以下になります --- no python application found, check your startup logs for errors --- [pid: 9740|app: -1|req: -1/7] 127.0.0.1 () {40 vars in 772 bytes} [Sun Feb 20 05:59:33 2022] GET / => generated 21 bytes in 0 msecs (HTTP/1.0 500) 2 headers in 83 bytes (0 s witches on core 0) --- no python application found, check your startup logs for errors --- [pid: 9740|app: -1|req: -1/8] 127.0.0.1 () {38 vars in 693 bytes} [Sun Feb 20 05:59:33 2022] GET /favicon.ico => generated 21 bytes in 0 msecs (HTTP/1.0 500) 2 headers in 83 bytes (0 switches on core 0) --- no python application found, check your startup logs for errors --- [pid: 9740|app: -1|req: -1/9] 127.0.0.1 () {38 vars in 588 bytes} [Sun Feb 20 05:59:52 2022] POST / => generated 21 bytes in 0 msecs (HTTP/1.0 500) 2 headers in 83 bytes (0 switches on core 0) --- no python application found, check your startup logs for errors --- [pid: 9740|app: -1|req: -1/10] 127.0.0.1 () {34 vars in 526 bytes} [Sun Feb 20 05:59:52 2022] GET /.env => generated 21 bytes in 0 msecs (HTTP/1.0 500) 2 headers in 83 bytes (0 switches on core 0) 正直何が原因で起きているのがさっぱりわかりません。。。
TaichiYanagiya

2022/02/20 07:23

> --- no python application found, check your startup logs for errors --- manage.py が読み込めていないようです。 manage.py は uwsgi を実行しているカレントディレクトリにあるのですか? uwsgi 起動時に "failed to open python file manage.py" などのログが出ていないでしょうか?
karun

2022/02/20 07:54

access.logやerror.logを見てもそのようなログは出ていませんでした。 ちなみに uwsgi --http :8000 --wsgi-file manage.py 実行後下記が出力しています *** Starting uWSGI 2.0.20 (64bit) on [Sun Feb 20 07:52:58 2022] *** compiled with version: 7.3.1 20180712 (Red Hat 7.3.1-13) on 30 January 2022 09:10:43 os: Linux-4.14.256-197.484.amzn2.x86_64 #1 SMP Tue Nov 30 00:17:50 UTC 2021 nodename: ip-10-0-10-10.ap-northeast-1.compute.internal machine: x86_64 clock source: unix detected number of CPU cores: 1 current working directory: /home/ec2-user/project detected binary path: /home/ec2-user/.local/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes detected max file descriptor number: 65535 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on :8000 fd 4 spawned uWSGI http 1 (pid: 11780) uwsgi socket 0 bound to TCP address 127.0.0.1:42779 (port auto-assigned) fd 3 Python version: 3.7.10 (default, Jun 3 2021, 00:02:01) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x14fcf30 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72904 bytes (71 KB) for 1 cores *** Operational MODE: single process *** unable to find "application" callable in file manage.py unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 11779, cores: 1)
TaichiYanagiya

2022/02/21 01:04

> unable to find "application" callable in file manage.py uwsgi は application() を実行しようとしますが、manage.py に見つからないということです。 manage.py を修正するか、"--callable=関数名" で呼び出す関数を指定するといいと思います。
karun

2022/02/23 02:33

TaichiYanagiyaさん --callable=関数名 で呼び出す関数をしていてみましたが結果は同じでした ちなみになんですが現時点で対象のURLにアクセスを行うと説明に出ているエラーが出てきています。 yu_1985さんがおっしゃっているホームディレクトリに配置していることが原因の一つとしてありえるのでしょうか?
TaichiYanagiya

2022/02/23 02:53

uwsgi 起動ログも「unable to find "関数名" callable in file manage.py」のままですか? おかしいですね。 > yu_1985さんがおっしゃっているホームディレクトリに配置していることが原因の一つとしてありえるのでしょうか? nginx とのインターフェースは TCP (127.0.0.1:8000) なので、ファイル・ディレクトリのパーミッションは関係ないと思うのですが。 まずは、uwsgi を正常に起動して、"curl http://127.0.0.1:8000/" でアクセスできるところを目標にしましょう。 その後、nginx 経由でアクセスできるかどうか、試すといいと思います。
karun

2022/02/23 08:22

>nginx とのインターフェースは TCP (127.0.0.1:8000) なので、ファイル・ディレクトリのパーミッションは関係ないと思うのですが。 こちらのことは承知いたしました。サイト通りにやってみて同じ結果が出ないのが不思議です。。。 本日https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.htmlのサイトの手順を一回試してみましたが「HelloWorld」がでることはありませんでした。。。 その後試しに「uwsgi --http :8000 --wsgi-file manage.py」を実行したら違うエラーになりました。。。 *** Starting uWSGI 2.0.20 (64bit) on [Wed Feb 23 08:13:33 2022] *** compiled with version: 7.3.1 20180712 (Red Hat 7.3.1-13) on 23 February 2022 07:28:32 os: Linux-4.14.256-197.484.amzn2.x86_64 #1 SMP Tue Nov 30 00:17:50 UTC 2021 nodename: ip-10-0-10-10.ap-northeast-1.compute.internal machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: /home/ec2-user/project detected binary path: /home/ec2-user/.local/bin/uwsgi *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes detected max file descriptor number: 65535 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on :8000 fd 4 spawned uWSGI http 1 (pid: 11419) uwsgi socket 0 bound to TCP address 127.0.0.1:43815 (port auto-assigned) fd 3 Python version: 3.7.10 (default, Jun 3 2021, 00:02:01) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x18dc780 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72920 bytes (71 KB) for 1 cores *** Operational MODE: single process *** Traceback (most recent call last): File "./project/wsgi.py", line 16, in <module> application = get_wsgi_application() File "/usr/local/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 301, in import_models self.models_module = import_module(models_module_name) File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/models.py", line 3, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/usr/local/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "/usr/local/lib/python3.7/site-packages/django/db/models/options.py", line 207, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/usr/local/lib/python3.7/site-packages/django/utils/connection.py", line 15, in __getattr__ return getattr(self._connections[self._alias], item) File "/usr/local/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__ conn = self.create_connection(alias) File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection backend = load_backend(db['ENGINE']) File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 73, in <module> check_sqlite_version() File "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 69, in check_sqlite_version 'SQLite 3.9.0 or later is required (found %s).' % Database.sqlite_version django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17). unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 11418, cores: 1) 調べてみたらSQLite3.7.17だからNGみたいでしたので 最新版をインストールしてみたのですが結果はこのままでした (env) [ec2-user@ip-10-0-10-10 ~]$ sqlite3 -version 3.38.0 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab sqlite> select sqlite_version(); 3.38.0 バージョン上げてるのにこのエラーが出てくるし意味がわからないです。。。
guest

回答1

0

自己解決

EC2を1から作り直したのとdjangoのバージョンが最新であったので②のサイト同様のバージョンで行った結果思うようになったので一旦完了といたします。
ご質問にご回答していただいた方々ありがとうございました。

投稿2022/02/27 09:19

karun

総合スコア18

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問