Dockerfile
FROM python:3.7.5
WORKDIR /home
RUN pip install django==3.2.3
RUN pip install uwsgi
RUN pip install pymysql
EXPOSE 8080
docker build -t django .
docker images #查看镜像是否成功
docker run -itd -p 8080:8080 --name=django -v /www/wwwroot/pyxfcrm:/home django
docker ps #查看docker是否启动
nginx配置
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass http://172.17.0.3:8080; #cat /etc/hosts 查看django的ip
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
uwsgi.ini配置
[uwsgi]
#配置和nginx连接的socket连接
#socket=0.0.0.0:8080
#也可以使用http
http=0.0.0.0:8080
#配置项目路径,项目的所在目录
chdir=/home
#配置wsgi接口模块文件路径
wsgi-file=xfcrm/wsgi.py
#配置启动的进程数
processes=40
#配置每个进程的线程数
threads=20
#配置启动管理主进程
master=True
#配置存放主进程的进程号文件
pidfile=uwsgi.pid
#配置dump日志记录
daemonize=uwsgi.log
#静态资源配置
static-map = /static=/home/index/static
静态资源配置
settings.py
import os
STATIC_ROOT =os.path.join(BASE_DIR,"index/static")
uwsgi命令
docker exec -it django /bin/bash
uwsgi --ini uwsgi.ini #启动
lsof -i :8001 #按照端口号查询
ps aux | grep uwsgi #按照程序名查询
kill -9 13844 #杀死进程
uwsgi --stop uwsgi.pid #通过uwsg停止uwsgi
uwsgi --reload uwsgi.pid #重启
网友评论