总体文件结构
docker-compose.yml文件
version: "3" # volumes: # 自定义数据卷 networks: # 自定义网络(默认桥接) web_network: driver: bridge services: web: build: ./serve ports: - "8000:8000" tty: true volumes: - ./serve:/var/www/django # 挂载项目代码 expose: - "8000" networks: - web_network restart: always privileged: true environment: TZ: Asia/Shanghai command: bash -c "/var/www/django/start.sh" nginx: image: nginx:1.20.2 restart: always depends_on: - web links: - "web:web" privileged: true networks: - web_network ports: - "8080:8080" volumes: - ./nginx/web-vue:/var/www/web-vue - ./nginx/conf:/etc/nginx/conf.d/ # 挂载nginx配置文件 - ./nginx/log:/var/log/nginx minio: image: minio/minio:latest command: server /data --console-address ":9090" restart: always privileged: true environment: - MINIO_ROOT_USER=admin - MINIO_ROOT_PASSWORD=admin123456 ports: - "9000:9000" - "9090:9090" networks: - web_network expose: - "9000" volumes: - ./minio_data:/data
Dockerfile文件
# 建立 python 3.9环境 FROM python:3.9 # 安装netcat RUN apt-get update && apt install -y netcat # 设置 python 环境变量 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # 可选:设置镜像源为国内 COPY pip.conf /root/.pip/pip.conf # 容器内创建 myproject 文件夹 ENV APP_HOME=/var/www/django RUN mkdir -p $APP_HOME WORKDIR $APP_HOME # 将当前目录加入到工作目录中(. 表示当前目录) ADD . $APP_HOME # 更新pip版本 RUN /usr/local/bin/python -m pip install --upgrade pip # 安装项目依赖 RUN pip install -r requirments.txt # 移除\r in windows RUN sed -i 's/\r//' ./start.sh # 给start.sh可执行权限 RUN chmod +x ./start.sh CMD ["/var/www/django/start.sh"]
start.sh文件
#! /bin/bash pkill -f uwsgi -9 nohup uwsgi --ini /var/www/django/uwsgi.ini >/dev/null 2>log & echo $(date +%Y-%m-%d\ %H:%M:%S) /bin/bash
uwsgi.ini文件
[uwsgi] master=true enable-threads=true #uwsgi监听的端口 # socket = 127.0.0.1:8811 http = 0.0.0.0:8000 chdir = /var/www/django/ wsgi-file = DjTe/wsgi.py #uwsgi启动进程数 processes = 4 threads = 10 #最大接收的请求数 max-requests = 1000 #buffer缓冲区大小 buffer-size = 30000 #进程pid存放路径 pidfile = /run/uwsgi-bbs.pid touch-chain-reload = true #uwsgi日志存储路径 daemonize = /var/www/django/logs/uwsgi.log # touch-logreopen = /var/www/django/logs/touchforlogrotate lazy-apps = true py-autoreload = 1
nginx配置文件文章来源:https://www.toymoban.com/news/detail-482163.html
upstream nginx_web{ ip_hash; server web:8000; } server { listen 8080; server_name localhost; charset utf-8; client_max_body_size 200m; # 允许客户端请求的最大单文件字节数 client_body_buffer_size 128k; # 缓冲区代理缓冲用户端请求的最大字节数 proxy_connect_timeout 90; # nginx跟后端服务器连接超时时间(代理连接超时) proxy_send_timeout 90; # 后端服务器数据回传时间(代理发送超时) proxy_read_timeout 90; # 连接成功后,后端服务器响应时间(代理接收超时) proxy_buffer_size 4k; # 设置代理服务器保存用户头信息的缓冲区大小 proxy_buffers 4 32k; # proxy_buffers缓冲区,网页平均在32k以下的话这样设置 proxy_busy_buffers_size 64k; # 高负荷下缓冲大小(proxy_buffers*2) proxy_temp_file_write_size 64k; # 设定缓存文件夹大小,大于这个值,将从upstream服务器传 location / { root /var/www/web-vue; index index.html index.htm; try_files $uri $uri/ /index.html; } location ^~/api/ { include /etc/nginx/uwsgi_params; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://nginx_web/; } location @router { rewrite ^.*$ /index.html last; #vue路由拦截 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
文章来源地址https://www.toymoban.com/news/detail-482163.html
到了这里,关于docker-compose部署django+nginx+minio的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!