django == 1.11.16
nginx == 1.10.3


程序编写

安装nginx

配置uwsgi

  • 创建 xxx.ini 文件
1
2
3
4
5
6
7
[uwsgi]
socket=:9000 # 端口
chdir=/mnt/project/project_api # 程序路径 包含manage.py的路径
module=pro.wsgi #pro为包含wsgi.py文件的文件名
master=true
processes=4
vacuum=true

配置nginx

  • 打开/etc/nginx/nginx.conf文件http{}中添加一个server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
listen 80;
server_name 域名 或者 localhost;
charset UTF-8;
access_log /var/log/nginx/djangohost.access.log;
error_log /var/log/nginx/djangohost.error.log;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
uwsgi_read_timeout 2;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
  • 重启nginx
1
2
3
4
5
ps -ef | grep nginx
kill -HUP < pid >

# 或者使用 service
service nginx restart
  • 启动程序
1
uwsgi --ini xxx.ini