Django 部署(Nginx+uwsgi)

使用 uwsgi 来部署

安装 uwsgiphp

sudo pip install uwsgi --upgradecss

使用 uwsgi 运行项目html

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

这样就能够跑了,project.wsgi 指的是 project/wsgi.py 文件bash

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

先编写uwsgi.ini文件:socket

[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访问。spa

安装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; } }
相关文章
相关标签/搜索