在机器上先安装好docker,nginx,mysql
安装镜像,启动容器
#上传项目到/application/opt/mg docker run -itd --name mg -v /application/opt/mg:/usr/src/mg -p 8002:8002 -d django docker exec -it mg /bin/bash pip install pymysql python /usr/src/mg/manage.py runserver 0.0.0.0:8002
修改静态文件路径
1.将项目的settings.py文件底部添加 STATIC_ROOT = os.path.join(BASE_DIR, "static_all") 2.生成静态文件 python manage.py collectstatic
创建数据库
#进入数据库 create database mg charset=utf8; #迁移数据 docker exec -it mg /bin/bash #cd /usr/src/mg python manage.py migrate
配置nginx反向代理
vim /etc/nginx/nginx.conf worker_processes 8; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #配置反向代理 server { listen 80; server_name 127.0.0.1; location / { proxy_pass http://127.0.0.1:8002/; } #静态文件配置 location /static/{ alias /application/opt/mg/static_all/; index index.html index.htm; } } }