feat(config): 更新环境配置和Nginx设置以支持动态端口配置
- 修改 .env.example 文件中的客户端API基础路径配置 - 将Dockerfile中的nginx.conf复制到模板目录以支持环境变量 - 在nginx配置中使用环境变量替换硬编码端口 - 为API文档路径(/docs、/redoc、/openapi.json)添加代理配置 - 移除硬编码的服务器地址,改用相对路径配置 - 更新docker-compose.yml以传递内部端口环境变量 - 简化nginx反向代理配置,移除冗余的服务器块配置
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ RUN npm run build:h5
|
||||
|
||||
FROM ${CLIENTS_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/build/h5 /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
+30
-3
@@ -1,12 +1,12 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen ${CLIENTS_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,14 +1,12 @@
|
||||
// #ifdef H5
|
||||
const API_BASE = import.meta.env.VITE_CLIENT_H5_API_BASE || "/api/v1";
|
||||
const SERVER_ORIGIN =
|
||||
import.meta.env.VITE_CLIENT_H5_SERVER_ORIGIN || window.location.origin;
|
||||
const SERVER_ORIGIN = import.meta.env.VITE_CLIENT_H5_SERVER_ORIGIN || "";
|
||||
// #endif
|
||||
|
||||
// #ifndef H5
|
||||
const API_BASE =
|
||||
import.meta.env.VITE_CLIENT_NATIVE_API_BASE || "http://10.0.10.11:8000/api/v1";
|
||||
const SERVER_ORIGIN =
|
||||
import.meta.env.VITE_CLIENT_NATIVE_SERVER_ORIGIN || "http://10.0.10.11:8000";
|
||||
import.meta.env.VITE_CLIENT_NATIVE_API_BASE || "/api/v1";
|
||||
const SERVER_ORIGIN = import.meta.env.VITE_CLIENT_NATIVE_SERVER_ORIGIN || "";
|
||||
// #endif
|
||||
|
||||
export { API_BASE, SERVER_ORIGIN };
|
||||
|
||||
Reference in New Issue
Block a user