django 部署上线 uwsgi+nginx+django
1:uwsgi
安装: pip3 install uwsgi
uwsgi 配置文件
vim uwsgi.ini
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# uwsig使用配置文件启动 [uwsgi] # 项目目录 chdir=/项目路径(DJANGO的) # 指定项目的application module=CMDB.wsgi:application # 指定sock的文件路径 socket=/xx/django_uwsgi.sock # 进程个数 workers=5 pidfile=/xx/uwsgi.pid # 指定IP端口 http=0.0.0.0:199 # 指定静态文件 static-map=/static=/代码路径/项目/静态文件路径 # 启动uwsgi的用户名和用户组 uid=root gid=root # 启用主进程 master=true # 自动移除unix Socket和pid文件当服务停止的时候 vacuum=true # 序列化接受的内容,如果可能的话 thunder-lock=true # 启用线程 enable-threads=true # 设置自中断时间 harakiri=30 # 设置缓冲 post-buffering=4096 # 设置日志目录 daemonize=/log/django_uwsgi.log
uwsgi --ini uwsgi.ini
之后就启动了。我的配置中是启动在199端口了
2:配置nginx
yum install -y nginx
vim /etc/nginx/nginx.conf
在http段落中加入
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
server { listen 8080; server_name ip; index index.php index.html; location / { include uwsgi_params; uwsgi_pass unix:/xx/django_uwsgi.sock; uwsgi_param UWSGI_CHDIR /xx; uwsgi_param UWSGI_SCRIPT django_wsgi; access_log /etc/nginx/logs/access.log; } location /static { alias /xx/arya/static; } }
最后 location /static 关系到 代理后 静态文件的问题;
3:django
pip3 install django
之后代码下载下来,放入对应目录即可
启动nginx, proxy_pass unix (uwsgi的socket)
和 php-fpm类似 也可以通过ip port 方式
server { listen 8080; server_name 47.93.86.201; index index.php index.html; location / { include uwsgi_params; #uwsgi_pass 47.93.86.201:199; uwsgi_pass unix:/mnt/www/django_uwsgi.sock; uwsgi_param UWSGI_CHDIR /mnt/www/cmdb/CMDB; uwsgi_param UWSGI_SCRIPT django_wsgi; access_log /etc/nginx/logs/access.log; } location /static { alias /mnt/www/cmdb/CMDB/arya/static; }#location ~ .*\.(js|css|gif)$ {# proxy_pass http://127.0.0.1:8080/static;#} }