您将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 的主机。使用 uwsgi 模块结合 virtualenv 可以非常方便地部署 WSGI 应用程序。
如果您的主机不允许您打开端口,您可以将 uwsgi 配置为使用 unix 套接字。
我写了一篇博客文章,解释了一次如何在 uwsgi + nginx 后面部署 Django,您可能希望以此为起点来玩转部署设置:http ://blog.johannesklug.de/2012/11/27/deploying -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;
}
}