1.安装uswgi
http://blog.csdn.net/a_little_snail/article/details/78040199
http://blog.csdn.net/a_little_snail/article/details/78040284
3.链接uwsgi和django接下来配置Django与uwsgi连接。此处,假定的我的django项目位置为:/home/jasonhaven/workspace/HomeMe
测试uswgi
Create a file called test.py
:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
运行:
uwsgi --http :8000 --wsgi-file test.py
访问django
uwsgi启动django
uwsgi --http :8001 --chdir /home/jasonhaven/workspace/HomeMe/ --wsgi-file HomeMe/wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
通过
Django
创建
myweb
项目时,在子目录
myweb
下已经帮我们生成的
wsgi.py
文件。所以,我们只需要再创建
myweb_uwsgi.ini
配置文件即可,当然,
uwsgi
支持多种类型的配置文件,如
xml
,
ini
等。此处,使用
ini
类型的配置。
# myweb_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8000
# the base directory (full path)
chdir = /home/jasonhaven/workspace/HomeMe
# Django s wsgi file
module = HomeMe.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
uwsgi --ini myweb_uwsgi.ini#通过uwsgi命令读取myweb_uwsgi.ini文件启动项目
4.链接uwsgi、nginx、django
修改nginx.conf配置文件。打开/usr/local/nginx/conf/nginx.conf文件,添加如下内容
server {
listen 8099;
server_name 127.0.0.1
charset UTF-8;
access_log /var/log/nginx/HomeMe_access.log;
error_log /var/log/nginx/HomeMe_error.log;
client_max_body_size 15M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/jasonhaven/workspace/HomeMe/static/;
}
现在重新启动nginx,翻看上面重启动nginx的命令。然后,访问:http://127.0.0.1:8099/
6.效果如图: