-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
# 使用 Eclipse Temurin OpenJDK 17 作为基础镜像 | ||
FROM eclipse-temurin:17-jdk-alpine | ||
|
||
# 安装 Nginx | ||
RUN apk update && apk add nginx | ||
|
||
# 创建应用程序工作目录 | ||
WORKDIR /app | ||
|
||
# 复制后端构建好的 JAR 文件到容器中 | ||
COPY backend/target/backend-0.0.1.jar app.jar | ||
COPY backend/target/backend-0.0.1.jar /app/app.jar | ||
|
||
# 复制前端构建好的静态文件到 Nginx 的默认静态资源目录 | ||
COPY frontend/dist /usr/share/nginx/html | ||
|
||
# 复制前端构建好的静态文件到后端的静态资源目录 | ||
COPY frontend/dist /app/public | ||
# 复制 Nginx 配置文件 | ||
COPY base/nginx.conf /etc/nginx/nginx.conf | ||
|
||
# 设置环境变量 | ||
ENV JAVA_OPTS="" | ||
|
||
# 容器启动时执行的命令 | ||
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"] | ||
# 配置 Nginx 启动和 Java 后端应用启动 | ||
# 容器启动时,先启动 Nginx,然后启动后端 Java 应用 | ||
CMD ["sh", "-c", "nginx && java $JAVA_OPTS -jar /app/app.jar"] | ||
|
||
# 暴露应用端口 | ||
EXPOSE 8080 | ||
# 暴露 Nginx 监听的端口 | ||
EXPOSE 8081 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# nginx.conf | ||
user nginx; | ||
worker_processes 1; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include mime.types; | ||
default_type application/octet-stream; | ||
|
||
sendfile on; | ||
keepalive_timeout 65; | ||
|
||
# 前端静态文件 | ||
server { | ||
listen 8081; | ||
server_name localhost; | ||
|
||
# 前端静态资源目录 | ||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html index.htm; | ||
} | ||
|
||
# 转发 API 请求到后端服务 | ||
location /api/ { | ||
proxy_pass http://localhost:8080; | ||
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 X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
} |