【Python】Centos7下部署Django(nginx+gunicorn)

Table of Contents

概述

gunicorn作为Django的wsgi服务器,管理Django项目的动态文件
nginx作为反向代理服务器,代理Django项目的静态文件

  * 1
  * 2

系统环境

centos7 minimal
python2.7.6

  * 1
  * 2

安装虚拟环境

yum install virtualenv
pip install virtualenvwrapper
source /usr/bin/virtualenvwrapper.sh

mkvirtualenv myproject
workon myproject

  * 1
  * 2
  * 3
  * 4
  * 5
  * 6

安装项目的依赖包

pip freeze > requirements.txt
将requirements.txt上传
再在虚拟环境中: pip install -r requirements.txt

  * 1
  * 2
  * 3

安装Gunicorn

pip install gunicorn
安装完成后在项目的settings.py中的install_app加入gunicorn应用

  * 1
  * 2

安装Nginx

yum install nginx

vi /etc/nginx/nginx.conf

...
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass  http://127.0.0.1:8000;
            #root   html;
            #index  index.html index.htm;
        }
 ...


systemctl start nginx
systemctl enable nginx

![](/static/blog/img/csdnimg/newCodeMoreWhite.png)

  * 1
  * 2
  * 3
  * 4
  * 5
  * 6
  * 7
  * 8
  * 9
  * 10
  * 11
  * 12
  * 13
  * 14
  * 15
  * 16
  * 17
  * 18
  * 19
  * 20
  * 21
  * 22
  * 23

启动项目

# 到项目的目录中(manage.py同级),执行:

    nohup gunicorn mypoject.wsgi:application -b 127.0.0.1:8000 &

mypoject为项目名称,wsgi为项目目录下的wsgi.py文件,application固定写法

  * 1
  * 2
  * 3
  * 4
  * 5

0 评论

发表评论

精品游戏◆乐于分享


Title