nginx + uwsgi + centos7部署django
一、环境准备
1、安装python3
https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz tar -zxv -f Python-3.6.2.tgz cd Python-3.6.2 ./configure --prefix=/usr/local/python36 make && make install
2、安装venv
mkdir .virtualenvs /usr/local/python36/bin/python3 -m venv cmdb
二、部署代码
下载代码到/data/app
cd .virtualenvs/cmdb source bin/activate pip install -r /data/app/tabops/requirements.txt
pip install uwsgi
三、部署
1、生成静态文件、初始化数据
/root/.virtualvenvs/cmdb/bin/python /data/app/tabops/manage.py collectstatic /root/.virtualvenvs/cmdb/bin/python /data/app/tabops/manage.py makemigrations /root/.virtualvenvs/cmdb/bin/python /data/app/tabops/manage.py migrate
2、部署uwsgi
/data/app/tabops/uwsgi.ini
[uwsgi] # Django-related settings # the base directory (full path) chdir = /data/app/tabops # Django's wsgi file module = tabops.wsgi # the virtualenv (full path) # process-related settings # master master = true # maximum number of worker processes processes = 20 # the socket (use the full path to be safe socket = 127.0.0.1:7000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true virtualenv = /root/.virtualenvs/cmdb/ logto = /tmp/tabops.log
/root/.virtualenvs/cmdb/bin/uwsgi -i /data/app/tabops/uwsgi.ini
3、部署nginx
upstream django { server 127.0.0.1:7000; # for a web port socket (we'll use this first) } server { listen 8000; server_name www.tabops.com; # default_type application/json; # add_header Content-Type 'application/json;charset=UTF-8'; client_max_body_size 75M; access_log /data/logs/nginx/cmdb_access.log; location /static { alias 你的目录/Mxonline/static; # 指向django的static目录 alias /data/app/tabops/static; } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /data/server/nginx/conf/uwsgi_params; # the uwsgi_params file you installed } }
4、创建超级用户
/root/.virtualvenvs/cmdb/bin/python /data/app/tabops/manage.py createsuperuser
访问
http://ip:8000/admin