Skip to content

Commit

Permalink
初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
qixing-ai committed Sep 9, 2024
1 parent a3bf851 commit 76372b8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
21 changes: 14 additions & 7 deletions Dockerfile
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/auth/login", "/auth/register",
"/swagger-ui.html", "/swagger-ui/**",
"/v3/api-docs/**",
"/index.html", "/assets/**");
.excludePathPatterns("/auth/login", "/auth/register","/swagger-ui.html","/swagger-ui/**","/v3/api-docs/**");
}

}
4 changes: 0 additions & 4 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
spring:
application:
name: RapidDataChat-backend
web:
resources:
static-locations: file:/app/public/ # 实际前后端分离的话需要去掉这个配置

datasource:
url: jdbc:postgresql://pgvector:5432/RapidDataChat_db
username: root
Expand Down
36 changes: 36 additions & 0 deletions base/nginx.conf
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;
}
}
}

0 comments on commit 76372b8

Please sign in to comment.