### 1.虚拟环境

```shell
pip install virtualenvwrapper
whereis virtualenvwrapper
vim /root/.bashrc
    export WORKON_HOME=/root/.virtualenv
    source /usr/local/bin/virtualenvwrapper.sh
source ./.bashrc

mkvirtualenv jcfresh
```

### 2.git

```shell
pip install git
新建 /srv/project_name, 在/srv/项目名下
git init
git remote add origin https://gitee.com/xslee_ahnu/web_sjsc.git
git pull https://gitee.com/xslee_ahnu/web_sjsc.git master  # 拉取仓库代码
# git reset        /        git stash; git pull **; git stash pop
```

```python
拿到代码后:
1. python manage.py migrate 迁移文件已经生成

2. DEBUG = FALSE 导致static文件找不到, 解决办法:
    settings.py中
        STATIC_ROOT = os.path.join(BASE_DIR, 'static_dist')        # 新建static_dist目录, 指定收集静态文件目录
    
    一级urls.py中
        from django.views import static
        from django.conf import settings
        urlpatterns = [
            url(r'^media/(?P<path>.*)$', static.serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
            url(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='media'),
        ]
    python manage.py collectstatic
```

### 3.安装mysql

```
apt install mysql
```

### 4.安装uwsgi

```shell
pip install uwsgi

1. 启动命令
    uwsgi --http: :8000 --module web_sjss.wsgi --virtualenv=/root/.virtualenv/web_sjsc

2. 使用配置文件
项目根目录(/srv/web_sjsc)
vim project_name_uwsgi.ini
    [uwsgi]
    # 项目路径
    chdir = /srv/web_sjsc
    # Django项目的uwsgi
    module = web_sjsc.wsgi
    # 虚拟环境path
    home =  /root/.virtualenv/web_sjsc
    # port
    http = :8000
    socket = /srv/web_sjsc/web_sjsc.sock    # 配合nginx, 没有nginx使用http
    # 权限
    chmod-socket = 666
    # 关闭清内存
    vacuum = true


命令:
    uwsgi --ini project_name_uwsgi.ini
```

### 5.安装nginx

```nginx
apt install nginx
在/usr/local/nginx/conf/ 新建
vim project_name.conf  (web_sjsc.conf)
upstream web_sjsc{
    server unix:///srv/web_sjsc/web_sjsc.sock;
}

server {
    listen    8000;
    server_name 121.196.35.156;
    charset    utf-8;
    client_max_body_size    75M;

    location /static{
        alias /srv/web_sjsc/static_dist;
    }
    location / {
        uwsgi_pass    web_sjsc;    # 与upstream web_sjsc 保持一致
        include /usr/local/nginx/conf/uwsgi_params;
    }
}
```

### 6.supervisor管理uwsgi

```shell
pip install supervisor

项目根目录 (/srv/web_sjsc)

vim supervisor.conf
    [program:web_sjsc]
    command = uwsgi --ini web_sjsc_uwsgi.ini    # 启动uwsgi命令
    directory = /srv/web_sjsc    # 项目path
    startsecs = 0
    stopwaitsecs = 0
    autostart = true
    autorestart = true
    stdout_logfile = /srv/web_sjsc/log/supervisord.log    # 要提前建好log目录
    stderr_logfile = /srv/web_sjsc/log/supervisord.err
    [supervisord]
    loglevel = info

启动命令: 
supervisord -c supervisor.conf 
```

 

对代码的调整根据实际情况即可