Python 3とnginxを使用して、virtualenvで基本的なFlaskアプリケーションを提供したいと思います。私はページを参照しようとしたとき、私はエラーにFlaskアプリケーションを使用したuwsgiは "callable not foundまたはimport error"を返します
内部サーバーエラー
を取得しています。私はまた、エラーが私のuwsgi設定ファイル内にあると信じてくれる/var/log/uwsgi/app/myproj.log
のエラーを見ています。 nginxとuwsgiはうまく通信しているようです。ここで
は私のディレクトリ構造です:
/srv/http/myproj/
|----- setup.py
|----- env/
|----- myproj/
|----- __init__.py
|----- myproj.py
/etc/uwsgi/apps-enabled/
|----- myproj.ini
/etc/nginx/sites-enabled/
|----- myproj
は、ここで私は/var/log/uwsgi/app/myproj.log
に表示されるエラーです:
Thu Jun 8 00:00:41 2017 - *** Operational MODE: preforking ***
Thu Jun 8 00:00:41 2017 - unable to load app 0 (mountpoint='') (callable not found or import error)
Thu Jun 8 00:00:41 2017 - *** no app loaded. going in full dynamic mode ***
Thu Jun 8 00:00:41 2017 - *** uWSGI is running in multiple interpreter mode ***
Thu Jun 8 00:00:41 2017 - spawned uWSGI master process (pid: 14498)
Thu Jun 8 00:00:41 2017 - spawned uWSGI worker 1 (pid: 14504, cores: 1)
Thu Jun 8 00:00:41 2017 - spawned uWSGI worker 2 (pid: 14505, cores: 1)
Thu Jun 8 00:00:43 2017 - --- no python application found, check your startup logs for errors ---
[pid: 14505|app: -1|req: -1/1] 172.16.72.2() {46 vars in 726 bytes} [Thu Jun 8 00:00:43 2017] GET/=> generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
はここ/etc/uwsgi/apps-enabled/myproj.ini
です:
[uwsgi]
plugins = python3
venv = /srv/http/myproj/env
chdir = /srv/http/myproj
module = myproj:myproj
callable = app
私も(myproj
にmodule
設定してみました何も変わらなかったuwsgiログに)、myproj.myproj
(これはモジュールmyproj.myproj
が見つからなかったため、あまり成功しませんでした)。ここで
が/srv/http/myproj/myproj/myproj.py
です:
import flask
app = flask.Flask(__name__)
ここ/srv/http/myproj/myproj/__init__.py
です:
from myproj.myproj import app
ここ/etc/nginx/sites-enabled/myproj
です:
upstream myproj {
server unix:///run/uwsgi/app/myproj/socket fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location/{
uwsgi_pass myproj;
include /etc/nginx/uwsgi_params;
}
}
私は私の質問は簡単であると仮定します。私は間違って何をしているのですか?
編集:ケースで、それは重要:
# lsb_release -d
Description: Ubuntu 16.04.2 LTS
uwsgiなしでフラスコアプリを実行できますか?その後、uwsgiのみを使用しますか? – Nurjan
@Nurzhanはい、私はuwsgiなしでFlaskのアプリケーションを実行し、ブラウザを介してうまくアクセスすることができます。私はあなたがuwsgiについてのみ何を意味するのか正確には分かりませんが、 'uwsgi --ini /etc/uwsg/apps-available/myproj.ini --socket/run/uwsgi/app/myproj/socket'を実行すると、私はアップストリームに接続中に '(13:Permission denied) 'のため、nginxから' 502 Bad Gateway'エラーが発生します。 – Todd
uwsgiを使用してアプリケーションを起動すると、サーバーが正しく機能するかどうかを確認できます。私はgunicorn + nginxを使用し、nginxが502エラーを出すとき、通常、gunicornがバックエンドで実行されていないときに発生します。 uwsgiを正しく起動できるかどうかを確認してください。 – Nurjan