makeserver
テスト展開に使用します。この場合、次のように小さな runserver-Script をラップすることがよくあります (チュートリアルでも指摘されているように)。
#!/bin/env python
from wsgiref.simple_server import make_server
from yourapp.core import app # whereever your wsgi app lives
if __name__ == '__main__':
server = make_server('0.0.0.0', 6547, app)
print ('Starting up server on http://localhost:6547')
server.serve_forever()
Apache にデプロイする場合は、mod_wsgi モジュールが必要です。nginx または lighthttpd をサポートするホスティング サービスを利用することをお勧めします。WSGI アプリケーションは、uwsgi モジュールを virtualenv と組み合わせて使用することで、非常に便利にデプロイできます。
ホスティング事業者がポートを開くことを許可していない場合は、uwsgi を構成して unix ソケットを使用できます。
uwsgi + nginx の背後に Django を一度デプロイする方法を説明するブログ記事を書きました。 -django-behind-nginx-with-uwsgi-and-virtualenv/
注: make_server にフィードするのと同じアプリ オブジェクトを使用して、uwsgi はそのワーカー プロセスを開始し、ソケットを開きます。
uwsgi のサンプル構成 (テストされていませんが、私のブログ投稿から抜粋):
# uwsgi.ini
[uwsgi]
# path to where you put your project code
chdir=/home/project/project
# if the app object resides in core.py
module=core:app
# this switch tells uwsgi to spawn a master process,
# that will dynamically spawn new child processes for
# server requests
master=True
# uwsgi stores the pid of your master process here
pidfile=/home/project/master.pid
vacuum=True
# path to your virtual environment, you should be using virtualenv
home=/home/project/env/
# path to log file
daemonize=/home/project/log
# this is where you need to point nginx to,
# if you chose to put this in project home make
# sure the home dir is readable and executable by
# nginx
socket=/tmp/uwsgi.sock
nginx のサンプル構成:
server {
listen 80;
server_name yourserver.example.org;
location / {
uwsgi_pass unix:///tmp/uwsgi.sock;
include uwsgi_params;
}
}