Nginx で uwsgi を使用して Python コードを実行しています。
uwsgi をディレクトリにバインドし、ブラウザでサーバーから呼び出した .py ファイルをレンダリングしたいと思います。ここでは PHP のように考えています (/index.php はそのファイルを実行し、/login.php はそのファイルを実行します)。
これは可能性がありますか?または、uwsgi で単一のモジュール/アプリ/ファイルを明示的に指定することしかできませんか?
これが私の初期化構文です:
/opt/uwsgi/uwsgi -s 127.0.0.1:9001 -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pidfile /var/run/uwsgi.pid --pythonpath /srv/www
/srv/www
.py ファイルが実行されるフォルダーとして機能できると思いました。
これが私のnginx構成です:
server {
listen 80;
server_name DONT_NEED_THIS;
access_log /srv/www/logs/access.log;
error_log /srv/www/logs/error.log;
location / {
root /srv/www;
# added lines
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
}
現状では、Web ルート (つまり、www.site.com/) を呼び出そうとすると、次のようになります。
wsgi application not found
次の index.py ファイルを使用します。
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
何か案は?
ありがとう!