私は(ほとんどの場合便宜上)html出力を生成する大量のpythonスクリプトを持っているので、当然、現在のテスト環境でスクリプトをホストするために非常に単純なセットアップを使用したいと思います。たとえば、Django、Flask、web2py などでプロジェクトをセットアップするのは面倒です。.py を作成して、php とほぼ同じように、他に何も構成せずに参照したいだけです。
何が問題なのか正確にわからないため、これに数日間苦労しているので、現在の試みを構成ファイルに投稿します。
nginx:
location ~ \.py$ {
uwsgi_pass unix:///path/to/socket;
uwsgi_param SCRIPT_NAME $uri;
include uwsgi_params;
}
uWSGI
[uwsgi]
plugins = python3
py-auto-reload = 1 #So I dont have to reload the service every time
test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return b"Hello World"
nginx と uwsgi の設定には多くのバリエーションがありますが、常に次のようになります。
uWSGI エラー
Python アプリケーションが見つかりません
そして、ログには常に次のようなものが表示されます。
[pid: 10423|app: -1|req: -1/10] 10.0.20.101 () {42 vars in 675 bytes} [Sun Oct 6 08:25:51 2013] GET /test.py => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
-
Sun Oct 6 08:26:44 2013 - unable to load app 0 (mountpoint='/var/www/test.py') (callable not found or import error)
[pid: 10423|app: -1|req: -1/12] 10.0.20.101 () {44 vars in 707 bytes} [Sun Oct 6 08:26:44 2013] GET /test.py => generated 48 bytes in 0 msecs (H
TTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
-
Sun Oct 6 07:22:36 2013 - unable to load app 0 (mountpoint='/test.py') (callable not found or import error)
[pid: 10423|app: -1|req: -1/12] 10.0.20.101 () {44 vars in 707 bytes} [Sun Oct 6 08:26:44 2013] GET /test.py => generated 48 bytes in 0 msecs (H
TTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)