fix: 修复nginx
This commit is contained in:
2
.env
2
.env
@@ -3,6 +3,4 @@ API_URL=
|
|||||||
API_MODEL=
|
API_MODEL=
|
||||||
ANNOUNCEMENT_TEXT=
|
ANNOUNCEMENT_TEXT=
|
||||||
API_TIMEOUT=60
|
API_TIMEOUT=60
|
||||||
# 添加后端服务地址(请替换为你的实际公网IP或域名)
|
|
||||||
BACKEND_URL=http://localhost:8888
|
|
||||||
LOGIN_PASSWORD=
|
LOGIN_PASSWORD=
|
||||||
|
|||||||
@@ -3,14 +3,7 @@ API_KEY=
|
|||||||
API_URL=
|
API_URL=
|
||||||
API_MODEL=
|
API_MODEL=
|
||||||
API_TIMEOUT=60
|
API_TIMEOUT=60
|
||||||
|
|
||||||
# 公告文本
|
# 公告文本
|
||||||
ANNOUNCEMENT_TEXT=欢迎使用!
|
ANNOUNCEMENT_TEXT=欢迎使用!
|
||||||
|
|
||||||
# 后端服务地址(公网访问时需要设置为公网IP或域名)
|
|
||||||
# 本地开发时可以使用:http://backend:8888
|
|
||||||
# 公网访问时使用:http://your_public_ip:8888
|
|
||||||
BACKEND_URL=http://localhost:8888
|
|
||||||
|
|
||||||
# 登录配置(为空时不需要登录,否则需要经过登录接口验证)
|
# 登录配置(为空时不需要登录,否则需要经过登录接口验证)
|
||||||
LOGIN_PASSWORD=
|
LOGIN_PASSWORD=
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ services:
|
|||||||
- API_TIMEOUT=${API_TIMEOUT}
|
- API_TIMEOUT=${API_TIMEOUT}
|
||||||
- LOGIN_PASSWORD=${LOGIN_PASSWORD}
|
- LOGIN_PASSWORD=${LOGIN_PASSWORD}
|
||||||
- ANNOUNCEMENT_TEXT=${ANNOUNCEMENT_TEXT}
|
- ANNOUNCEMENT_TEXT=${ANNOUNCEMENT_TEXT}
|
||||||
- BACKEND_URL=${BACKEND_URL:-http://localhost:8888}
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -35,8 +34,6 @@ services:
|
|||||||
container_name: stock-scanner-frontend
|
container_name: stock-scanner-frontend
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
environment:
|
|
||||||
- BACKEND_URL=${BACKEND_URL:-http://backend:8888}
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -19,18 +19,12 @@ RUN npm run build
|
|||||||
# 生产阶段
|
# 生产阶段
|
||||||
FROM nginx:stable-alpine as production-stage
|
FROM nginx:stable-alpine as production-stage
|
||||||
|
|
||||||
# 复制自定义nginx配置(如需要)
|
# 复制自定义nginx配置
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf.template
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# 从构建阶段复制构建结果到nginx服务目录
|
# 从构建阶段复制构建结果到nginx服务目录
|
||||||
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# 创建启动脚本
|
|
||||||
RUN echo '#!/bin/sh' > /docker-entrypoint.sh && \
|
|
||||||
echo 'envsubst "$BACKEND_URL" < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf' >> /docker-entrypoint.sh && \
|
|
||||||
echo 'nginx -g "daemon off;"' >> /docker-entrypoint.sh && \
|
|
||||||
chmod +x /docker-entrypoint.sh
|
|
||||||
|
|
||||||
# 暴露80端口
|
# 暴露80端口
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
@@ -39,4 +33,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|||||||
CMD wget --quiet --tries=1 --spider http://localhost:80 || exit 1
|
CMD wget --quiet --tries=1 --spider http://localhost:80 || exit 1
|
||||||
|
|
||||||
# 设定启动命令
|
# 设定启动命令
|
||||||
CMD ["/docker-entrypoint.sh"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
@@ -13,49 +13,61 @@ server {
|
|||||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||||
}
|
}
|
||||||
|
|
||||||
# API请求代理到后端服务
|
# API请求代理到后端服务 - 使用相对路径
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass ${BACKEND_URL}/api/;
|
proxy_pass http://backend:8888/api/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection 'upgrade';
|
proxy_set_header Connection 'upgrade';
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
proxy_read_timeout 300s;
|
proxy_read_timeout 300s;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /login {
|
location /login {
|
||||||
proxy_pass ${BACKEND_URL}/login;
|
proxy_pass http://backend:8888/login;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /check_auth {
|
location /check_auth {
|
||||||
proxy_pass ${BACKEND_URL}/check_auth;
|
proxy_pass http://backend:8888/check_auth;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /need_login {
|
location /need_login {
|
||||||
proxy_pass ${BACKEND_URL}/need_login;
|
proxy_pass http://backend:8888/need_login;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /config {
|
location /config {
|
||||||
proxy_pass ${BACKEND_URL}/config;
|
proxy_pass http://backend:8888/config;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /analyze {
|
location /analyze {
|
||||||
proxy_pass ${BACKEND_URL}/analyze;
|
proxy_pass http://backend:8888/analyze;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
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_cache_bypass $http_upgrade;
|
proxy_cache_bypass $http_upgrade;
|
||||||
proxy_read_timeout 300s;
|
proxy_read_timeout 300s;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user