feat(config): 更新环境配置和Nginx设置以支持动态端口配置

- 修改 .env.example 文件中的客户端API基础路径配置
- 将Dockerfile中的nginx.conf复制到模板目录以支持环境变量
- 在nginx配置中使用环境变量替换硬编码端口
- 为API文档路径(/docs、/redoc、/openapi.json)添加代理配置
- 移除硬编码的服务器地址,改用相对路径配置
- 更新docker-compose.yml以传递内部端口环境变量
- 简化nginx反向代理配置,移除冗余的服务器块配置
This commit is contained in:
2026-05-09 18:08:16 +08:00
parent 9de0a56afa
commit f2b4beed0a
9 changed files with 74 additions and 119 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ RUN npm run build
FROM ${ADMIN_WEB_NGINX_IMAGE}
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/templates/default.conf.template
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
+30 -3
View File
@@ -1,12 +1,12 @@
server {
listen 80;
listen ${ADMIN_WEB_INTERNAL_PORT};
server_name _;
root /usr/share/nginx/html;
index index.html;
location /api/ {
proxy_pass http://server:8000/api/;
proxy_pass http://server:${SERVER_INTERNAL_PORT}/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -15,11 +15,38 @@ server {
}
location /uploads/ {
proxy_pass http://server:8000/uploads/;
proxy_pass http://server:${SERVER_INTERNAL_PORT}/uploads/;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /docs {
proxy_pass http://server:${SERVER_INTERNAL_PORT}/docs;
proxy_http_version 1.1;
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;
}
location = /redoc {
proxy_pass http://server:${SERVER_INTERNAL_PORT}/redoc;
proxy_http_version 1.1;
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;
}
location = /openapi.json {
proxy_pass http://server:${SERVER_INTERNAL_PORT}/openapi.json;
proxy_http_version 1.1;
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;
}
location / {
try_files $uri $uri/ /index.html;
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { clearAdminToken, getAdminToken, setAdminToken, setAdminUser } from './a
const API_BASE
= import.meta.env.VITE_API_BASE
|| (import.meta.env.DEV ? 'http://127.0.0.1:8000/api/v1' : '/api/v1')
|| '/api/v1'
type RequestError = Error & { status?: number }