1. 安装uWSGI
`pip install uwsgi`
阿里云ubuntu自带python2.7,在安装WSGI之前需要安装新版本的python,如python3.6,同时也要将Django项目中需要引用的包安装完成。
2.uWSGI配置文件
在uwsgi的文件夹中建立配置文件:
cd /etc/uwsgi/sites
如果没有sites文件夹,可以先创建该文件夹 mkdir 文件名
。
然后创建并编辑文件
vim project.ini
[uwsgi]
http = :8000
# the base directory (full path)
chdir = /root/path/to/project
# Django s wsgi file
module = project.wsgi
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
vacuum = true
3.Nginx的安装和配置
安装
apt-get install nginx
创建配置文件
vim /etc/nginx/sites-available/project
server {
listen 8001;
server_name ip; #服务器公网ip
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
location /static/ {
root root/path;#静态文件地址
}
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass unix:/path/project.sock;
}
}
4.启动
启动nginx:service nginx restart
启动uwsgi:uwsgi /etc/uwsgi/sites/project.ini