From 0dddcc8b3784da087cb86911d04358b61e567a89 Mon Sep 17 00:00:00 2001 From: 13066656961 <1622813142@qq.com> Date: Sat, 20 Jul 2024 21:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Dockerfile=20=E4=B8=8Enginx?= =?UTF-8?q?=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile-API | 11 ++++++++++ Dockerfile-Console | 14 +++++++++++++ snowy-admin-web/nginx.conf | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 Dockerfile-API create mode 100644 Dockerfile-Console create mode 100644 snowy-admin-web/nginx.conf diff --git a/Dockerfile-API b/Dockerfile-API new file mode 100644 index 00000000..583ac097 --- /dev/null +++ b/Dockerfile-API @@ -0,0 +1,11 @@ +FROM registry.cn-beijing.aliyuncs.com/mojiong/openjdk:17 + +# 将本地的 jar 文件添加到容器中并重命名为 app.jar +ADD snowy-web-app/target/snowy-web-app-3.0.0.jar app.jar + +# 暴露容器的端口,Spring Boot 默认端口为 8080 +EXPOSE 82 + +# 设置容器启动时运行的命令 +ENTRYPOINT ["java","-jar","/app.jar"] + diff --git a/Dockerfile-Console b/Dockerfile-Console new file mode 100644 index 00000000..88a3d335 --- /dev/null +++ b/Dockerfile-Console @@ -0,0 +1,14 @@ +FROM registry.cn-beijing.aliyuncs.com/mojiong/nginx:latest +ENV VAR_HOST Snowy-API +#RUN apt-get update && apt-get install -y vim +# 将本地的 html 文件添加到容器中并 +COPY snowy-admin-web/dist/ /usr/share/nginx/html +# 复制反向代理文件 +COPY snowy-admin-web/nginx.conf /etc/nginx/conf.d/default.conf +# 反向代理的域名替换 +RUN sed -i "s/\CONTAINER-HOST/${VAR_HOST}/g" /etc/nginx/conf.d/default.conf +# 暴露容器的端口,nginx默认端口为 80 +EXPOSE 80 + +# 设置容器启动时运行的命令 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/snowy-admin-web/nginx.conf b/snowy-admin-web/nginx.conf new file mode 100644 index 00000000..a7ca2112 --- /dev/null +++ b/snowy-admin-web/nginx.conf @@ -0,0 +1,41 @@ +server { + listen 80; + server_name localhost; + gzip on; + gzip_min_length 1k; + gzip_comp_level 9; + gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_vary on; + gzip_disable "MSIE [1-6]\."; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ @router; + error_page 405 =200 http://$host$request_uri; + } + + location @router { + rewrite ^.*$ /index.html last; + } + + location /api { + proxy_pass http://CONTAINER-HOST:82; + 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_set_header REMOTE-HOST $remote_addr; + + add_header X-Cache $upstream_cache_status; + + #Set Nginx Cache + rewrite ^/api/(.*)$ /$1 break; + add_header Cache-Control no-cache; + expires 12h; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } +}