使用 uwsgi 来部署

安装 uwsgi

sudo pip install uwsgi --upgrade

使用 uwsgi 运行项目

uwsgi --http :8001 --chdir /path/to/project  --module project.wsgi

这样就可以跑了,project.wsgi 指的是 project/wsgi.py 文件

这样只是测试,正式环境下:

先编写uwsgi.ini文件:

[uwsgi]
chdir=/home/soms
# Django项目根目录 (绝对路径)
module=soms.wsgi:application 
master=True 
# process-related settings
# master
pidfile=/home/soms/vm.pid 
vacuum=True
# clear environment on exit
max-requests=1000 
daemonize=/home/soms/v_uwsgi.log
socket = 0.0.0.0:10000
#真实服务的端口
#http = 0.0.0.0:9090

其中soms 改为只能项目名字就行。#是注释掉的,这里保留做学习助于理解。

启动:uwsgi --ini uwsgi.ini

启动成功后uwsgi会占用10000端口运行该项目,但要注意这里没配http,所以不能直接用http访问。

安装nginx

然后添加配置文件:

server
{
    listen 9090;
    server_name mytest.com;
    index index.html;
    location / {
        root /home/soms;
        uwsgi_pass 127.0.0.1:10000;
        include uwsgi_params;
        uwsgi_param UWSGI_CHDIR /home/soms;
        uwsgi_param UWSGI_SCRIPT wsgi;
    }
    location ~ .*\.(log|php|pl|py|sh|cgi)$ {
        return 403;
    }
    location /static/ {
        root /home/soms;
        access_log off;
    }
    location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
        root /home/soms;
        expires 30d;
    }
    location ~ .*\.(js|css)?(.*)
    {
        root /home/soms;
        expires      12h;
    }
}

 

posted on 2018-07-27 09:50  聪神carry  阅读(135)  评论(0编辑  收藏  举报