From cbb0cb76b58ff733fada124c5ae0cf72a781db87 Mon Sep 17 00:00:00 2001 From: good luck <1204505056@qq.com> Date: Mon, 10 May 2021 20:16:14 +0800 Subject: [PATCH] add docker --- .dockerignore | 1 + Dockerfile | 37 ++++++++++++++++++++++++++++++++ deploy-docker-compose.sh | 5 +++++ deploy-docker.sh | 7 ++++++ docker-compose.yml | 14 ++++++++++++ nginx.conf | 45 +++++++++++++++++++++++++++++++++++++++ nginx.default.conf | 46 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 155 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 deploy-docker-compose.sh create mode 100644 deploy-docker.sh create mode 100644 docker-compose.yml create mode 100644 nginx.conf create mode 100644 nginx.default.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..86895cd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM nginx + +MAINTAINER vue-admin-beautiful +LABEL description=本项目基于vue-admin-beautiful开源版构建 +LABEL qq=783963206 + +# 环境变量 +ENV TZ=Asia/Shanghai \ + RUN_USER=nginx \ + RUN_GROUP=nginx \ + DATA_DIR=/data/web \ + LOG_DIR=/data/log/nginx + +# 工作目录 +WORKDIR ${DATA_DIR} + +# 日志输出 +RUN ["echo","vue-admin-beautiful - UI building..."] + +# 切换为上海时区 +RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \ + && echo $TZ > /etc/timezone + +# 创建日志文件夹 +RUN mkdir ${LOG_DIR} -p +RUN chown nginx.nginx -R ${LOG_DIR} + +# 拷贝dist包文件 +COPY ./dist ./ + +# 拷贝nginx配置文件 +ADD nginx.conf /etc/nginx/nginx.conf +ADD nginx.default.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +ENTRYPOINT nginx -g "daemon off;" diff --git a/deploy-docker-compose.sh b/deploy-docker-compose.sh new file mode 100644 index 0000000..82bed42 --- /dev/null +++ b/deploy-docker-compose.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +npm run build + +docker-compose up -d \ No newline at end of file diff --git a/deploy-docker.sh b/deploy-docker.sh new file mode 100644 index 0000000..4be2c81 --- /dev/null +++ b/deploy-docker.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +npm run build + +docker build -t vue-admin-beautiful . + +docker run --name vue-admin-beautiful --restart=always -p 80:80 -v /var/nginx:/var/data -d vue-admin-beautiful \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c1a86ca --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.3' +services: + vue-admin-beautiful: + build: ./ + restart: always + container_name: vue-admin-beautiful + image: vue-admin-beautiful + environment: + TZ: Asia/Shanghai + LANG: en_US.UTF-8 + volumes: + - /var/nginx:/var/data #挂载 Nginx 文件 + ports: + - "80:80" diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..e9b54e6 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,45 @@ +user nginx; +worker_processes auto; +pid /var/run/nginx.pid; + +events { + use epoll; + worker_connections 51200; + multi_accept on; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server_names_hash_bucket_size 512; + client_header_buffer_size 32k; + large_client_header_buffers 4 32k; + client_max_body_size 50m; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + + keepalive_timeout 65; + + # gzip 压缩 + gzip on; + gzip_min_length 1k; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 2; + gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; + gzip_vary on; + gzip_proxied expired no-cache no-store private auth; + gzip_disable "MSIE [1-6]\."; + + limit_conn_zone $binary_remote_addr zone=perip:10m; + limit_conn_zone $server_name zone=perserver:10m; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/nginx.default.conf b/nginx.default.conf new file mode 100644 index 0000000..e602ce3 --- /dev/null +++ b/nginx.default.conf @@ -0,0 +1,46 @@ +server { + listen 80; + server_name localhost; + + access_log /data/log/nginx/access.log main; + error_log /data/log/nginx/error.log; + + # 静态资源 + location / { + root /data/web; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + # 前端代理 + location ^~ /后端服务名 { + proxy_pass http://后端服务IP地址:8080; + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Credentials: true; + add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE; + + proxy_http_version 1.1; + # 连接延时 + proxy_connect_timeout 3600s; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + # IP 穿透 + proxy_set_header Host $proxy_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # WebSocket 穿透 + proxy_set_header Origin ""; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} +} +