码迷,mamicode.com
首页 > 其他好文 > 详细

django2.1+uwsgi+nginx部署

时间:2020-02-07 19:12:10      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:conf   stream   art   ams   request   add   false   media   module   

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部署

标签:conf   stream   art   ams   request   add   false   media   module   

原文地址:https://www.cnblogs.com/CodingLife-190505/p/12273707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!