django2.1+uwsgi+nginx部署
Posted codinglife-190505
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django2.1+uwsgi+nginx部署相关的知识,希望对你有一定的参考价值。
1安装uwsgi
pip3 install uwsgi
2安装nginx
sudo apt install nginx -y
3配置uwsgi与nginx连接
在项目根目录下执行命令: (注意:后面这个空格+点儿别落下)
cp /etc/nginx/uwsgi_params .
4配置uwsgi.ini
vim uwsgi.ini
然后加入以下内容:
[uwsgi] chdir=/home/admin/community module=community.wsgi:application master=true processes=5 socket=:8001 chmod-socket = 666 vacuum=true
5配置nginx
#cd 到项目目录下
vim community.conf
#粘贴以下内容 upstream django { # server unix:/root/xueyiwang/xueyiwang.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we‘ll use this first) } # configuration of the server server { # the port your site will be served on listen 8000; # the domain name it will serve for server_name 你自己的公网IP; # substitute your machine‘s IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /你自己的项目根目录/media; # your Django project‘s media files - amend as required } location /static { alias /你自己的项目根目录/static_common; # your Django project‘s static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /你自己的项目根目录/uwsgi_params; # the uwsgi_params file you installed } }
6建立软链接
sudo ln -s /你自己的项目根目录/community.conf /etc/nginx/sites-enabled/
7收集静态文件
#cd 到项目目录下执行命令
python manage.py collectstatic
将项目的所以静态文件收集到STATIC_ROOT指定的目录里
8修改setting.py
ALLOWED_HOSTS = [‘公网IP‘] #自己的服务器公网IP DEBUG = False #在最底追加 STATIC_ROOT=os.path.join(BASE_DIR,"static_common").replace("\\ ","/")
9在项目根目录下执行命令
创建数据库表
python manage.py migrate
10在项目根目录下执行命令:
cd ..
sudo service nginx restart #重启nginx uwsgi --ini uwsgi.ini #启动uwsgi
转:https://www.cnblogs.com/xuepangzi/p/9219207.html
以上是关于django2.1+uwsgi+nginx部署的主要内容,如果未能解决你的问题,请参考以下文章