添加Dockerfile 与nginx反向代理文件

pull/236/head
13066656961 2024-07-20 21:00:00 +08:00
parent 60addecd54
commit 0dddcc8b37
3 changed files with 66 additions and 0 deletions

11
Dockerfile-API Normal file
View File

@ -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"]

14
Dockerfile-Console Normal file
View File

@ -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;"]

View File

@ -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;
}
}