總體文件結(jié)構(gòu)
?
docker-compose.yml文件
version: "3" # volumes: # 自定義數(shù)據(jù)卷 networks: # 自定義網(wǎng)絡(luò)(默認橋接) 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環(huán)境 FROM python:3.9 # 安裝netcat RUN apt-get update && apt install -y netcat # 設(shè)置 python 環(huán)境變量 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # 可選:設(shè)置鏡像源為國內(nèi) COPY pip.conf /root/.pip/pip.conf # 容器內(nèi)創(chuàng)建 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可執(zhí)行權(quán)限 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監(jiān)聽的端口 # socket = 127.0.0.1:8811 http = 0.0.0.0:8000 chdir = /var/www/django/ wsgi-file = DjTe/wsgi.py #uwsgi啟動進程數(shù) processes = 4 threads = 10 #最大接收的請求數(shù) max-requests = 1000 #buffer緩沖區(qū)大小 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配置文件文章來源:http://www.zghlxwxcb.cn/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; # 允許客戶端請求的最大單文件字節(jié)數(shù) client_body_buffer_size 128k; # 緩沖區(qū)代理緩沖用戶端請求的最大字節(jié)數(shù) proxy_connect_timeout 90; # nginx跟后端服務器連接超時時間(代理連接超時) proxy_send_timeout 90; # 后端服務器數(shù)據(jù)回傳時間(代理發(fā)送超時) proxy_read_timeout 90; # 連接成功后,后端服務器響應時間(代理接收超時) proxy_buffer_size 4k; # 設(shè)置代理服務器保存用戶頭信息的緩沖區(qū)大小 proxy_buffers 4 32k; # proxy_buffers緩沖區(qū),網(wǎng)頁平均在32k以下的話這樣設(shè)置 proxy_busy_buffers_size 64k; # 高負荷下緩沖大?。╬roxy_buffers*2) proxy_temp_file_write_size 64k; # 設(shè)定緩存文件夾大小,大于這個值,將從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; } }
?文章來源地址http://www.zghlxwxcb.cn/news/detail-482163.html
到了這里,關(guān)于docker-compose部署django+nginx+minio的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!