-----
This commit is contained in:
@ -10,7 +10,7 @@ VITE_PUBLIC_PATH = /
|
|||||||
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
|
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
|
||||||
# 可以有多个,注意多个不能换行,否则代理将会失效
|
# 可以有多个,注意多个不能换行,否则代理将会失效
|
||||||
#VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]]
|
#VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]]
|
||||||
VITE_PROXY=[["/api","http://127.0.0.1:8090"]]
|
VITE_PROXY=[["/api","http://back.ges.bjgastx.com"]]
|
||||||
|
|
||||||
# 是否删除Console.log
|
# 是否删除Console.log
|
||||||
VITE_DROP_CONSOLE = false
|
VITE_DROP_CONSOLE = false
|
||||||
|
|||||||
@ -18,7 +18,8 @@ VITE_BUILD_COMPRESS = 'gzip'
|
|||||||
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
|
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false
|
||||||
|
|
||||||
# 接口地址 可以由nginx做转发或者直接写实际地址
|
# 接口地址 可以由nginx做转发或者直接写实际地址
|
||||||
VITE_GLOB_API_URL=${location.origin}/api
|
#VITE_GLOB_API_URL=${location.origin}/api
|
||||||
|
VITE_GLOB_API_URL=/api
|
||||||
#VITE_GLOB_API_URL=http://10.4.126.112:23000
|
#VITE_GLOB_API_URL=http://10.4.126.112:23000
|
||||||
VITE_GLOB_REQUEST_TIMEOUT=600000
|
VITE_GLOB_REQUEST_TIMEOUT=600000
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ VITE_GLOB_REQUEST_TIMEOUT=600000
|
|||||||
VITE_GLOB_UPLOAD_URL = /system/oss/upload
|
VITE_GLOB_UPLOAD_URL = /system/oss/upload
|
||||||
|
|
||||||
# 文件预览接口 可选
|
# 文件预览接口 可选
|
||||||
VITE_GLOB_UPLOAD_PREVIEW = http://114.116.210.204:8012/onlinePreview?url=
|
VITE_GLOB_UPLOAD_PREVIEW = /preview/onlinePreview?url=
|
||||||
|
|
||||||
#外部url地址
|
#外部url地址
|
||||||
VITE_GLOB_OUT_LINK_URL = ['http://114.116.210.204:4100']
|
VITE_GLOB_OUT_LINK_URL = ['http://114.116.210.204:4100']
|
||||||
|
|||||||
27
Dockerfile
27
Dockerfile
@ -1,23 +1,16 @@
|
|||||||
# 使用 Node.js 18 作为基础镜像
|
# 使用 Node.js 18 作为基础镜像
|
||||||
#FROM 10.4.117.234:8082/node:20-alpine
|
#FROM --platform=linux/arm64 docker.xuanyuan.run/library/node:20-alpine
|
||||||
FROM --platform=linux/arm64 docker.xuanyuan.run/library/node:20-alpine
|
FROM docker.tanuki.vip/nginx-amd64:1.29.0
|
||||||
|
MAINTAINER fucai
|
||||||
|
|
||||||
# 在容器中创建工作目录
|
WORKDIR /usr/share/nginx/html
|
||||||
WORKDIR /app
|
COPY ./nginx.conf /etc/nginx/nginx.conf # 拷贝 nginx 配置文件
|
||||||
|
COPY ./dist/ /usr/share/nginx/html/ # 拷贝 dist 目录下的文件到 nginx 的 html 目录下
|
||||||
|
|
||||||
# 拷贝整个应用程序到工作目录
|
EXPOSE 8080
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# 安装依赖
|
VOLUME ["/etc/nginx/nginx.conf", "/usr/share/nginx/html"]
|
||||||
RUN yarn install
|
|
||||||
|
|
||||||
# 构建应用程序
|
CMD ["nginx","-g","daemon off;"]
|
||||||
RUN yarn build
|
|
||||||
|
|
||||||
# 暴露端口
|
# docker build -t itc-web:1.0.0 .
|
||||||
EXPOSE 3100
|
|
||||||
|
|
||||||
# 运行应用程序
|
|
||||||
CMD [ "npm", "run", "serve" ]
|
|
||||||
|
|
||||||
#docker build -t pcitc/itc-web:1.0.0 .
|
|
||||||
|
|||||||
17
Dockerfile-arm64
Normal file
17
Dockerfile-arm64
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
FROM --platform=linux/arm64 docker.tanuki.vip/nginx-arm64:1.29.0
|
||||||
|
MAINTAINER fucai
|
||||||
|
|
||||||
|
|
||||||
|
WORKDIR /usr/share/nginx/html
|
||||||
|
COPY ./nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY ./dist/ /usr/share/nginx/html/
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
VOLUME ["/etc/nginx/nginx.conf", "/usr/share/nginx/html"]
|
||||||
|
|
||||||
|
CMD ["nginx","-g","daemon off;"]
|
||||||
|
|
||||||
|
# docker build -t itc-web-arm64:1.0.0 .
|
||||||
|
|
||||||
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
FROM --platform=linux/arm64 node-http-server:1.0.0
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY ./dist /app/html/
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
|
|
||||||
# docker build -f Dockerfile-vue -t pcitc/itc-web:1.0.2 .
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
==============================================
|
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼʱ<EFBFBD><EFBFBD>: 2025/08/07 <20><><EFBFBD><EFBFBD> 14:09:46.88
|
|
||||||
==============================================
|
|
||||||
======================
|
|
||||||
<EFBFBD><EFBFBD>Ŀ¼ ../
|
|
||||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼ ../dist
|
|
||||||
DockerĿ¼ F:\<5C><><EFBFBD>ݹ<EFBFBD>Ӧ<EFBFBD><D3A6>\code\study\itc-framework-front\docker\
|
|
||||||
----------------------
|
|
||||||
======================
|
|
||||||
2025/08/07 <20><><EFBFBD><EFBFBD> 14:09:47.02 <20><>ʼִ<CABC><D6B4>npm run build...
|
|
||||||
======================
|
|
||||||
151
nginx.conf
Normal file
151
nginx.conf
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
|
||||||
|
#user nobody;
|
||||||
|
|
||||||
|
# 工作进程数:自动匹配CPU核心数(比固定值更灵活)
|
||||||
|
worker_processes 4;
|
||||||
|
|
||||||
|
# 错误日志:开启并按级别分离(方便问题定位)
|
||||||
|
error_log /var/log/nginx/error.log notice;
|
||||||
|
pid /run/nginx.pid;
|
||||||
|
|
||||||
|
# 全局资源限制(避免文件描述符不足)
|
||||||
|
worker_rlimit_nofile 65535;
|
||||||
|
|
||||||
|
events {
|
||||||
|
# 每个工作进程最大连接数(结合系统ulimit调整)
|
||||||
|
worker_connections 8192;
|
||||||
|
# 高效事件模型(Linux推荐epoll,FreeBSD用kqueue)
|
||||||
|
use epoll;
|
||||||
|
# 一次性接受所有新连接(提高连接处理效率)
|
||||||
|
multi_accept on;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
http {
|
||||||
|
include mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
# 日志格式优化:增加响应时间和 upstream 信息(便于性能分析)
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for" '
|
||||||
|
'$request_time $upstream_response_time';
|
||||||
|
# 访问日志:开启(生产环境可按需关闭或调整路径)
|
||||||
|
access_log /var/log/nginx/access.log main;
|
||||||
|
|
||||||
|
# 高效文件传输
|
||||||
|
sendfile on;
|
||||||
|
# 静态文件传输优化(配合sendfile使用,减少TCP包数量)
|
||||||
|
tcp_nopush on;
|
||||||
|
# 动态内容优化(减少网络延迟)
|
||||||
|
tcp_nodelay on;
|
||||||
|
|
||||||
|
# 长连接设置
|
||||||
|
keepalive_timeout 65; # 连接超时时间
|
||||||
|
keepalive_requests 1000; # 每个连接最大请求数(防止长连接占用)
|
||||||
|
keepalive_disable msie6; # 对老旧IE禁用长连接
|
||||||
|
|
||||||
|
# 客户端请求限制(防攻击)
|
||||||
|
client_max_body_size 100m; # 缩小上传限制(1024m过大,按需调整)
|
||||||
|
client_body_buffer_size 1m; # 客户端请求体缓冲区(原1024k保留,单位统一)
|
||||||
|
client_body_timeout 120s; # 客户端发送请求体超时
|
||||||
|
client_header_timeout 120s; # 客户端发送请求头超时
|
||||||
|
|
||||||
|
|
||||||
|
# Gzip压缩优化
|
||||||
|
gzip on;
|
||||||
|
gzip_min_length 1k; # 最小压缩尺寸
|
||||||
|
gzip_comp_level 5; # 压缩级别(平衡CPU和带宽)
|
||||||
|
gzip_types
|
||||||
|
text/plain text/css text/xml application/json application/javascript application/x-javascript text/javascript application/xml application/xml+rss text/rss; # 明确需要压缩的类型
|
||||||
|
gzip_disable "MSIE [1-6]\."; # 禁用老旧IE压缩
|
||||||
|
gzip_vary on; # 告诉代理服务器缓存压缩和非压缩版本
|
||||||
|
gzip_buffers 16 8k; # 压缩缓冲区(默认值优化)
|
||||||
|
gzip_http_version 1.1; # 仅对HTTP/1.1及以上启用(避免兼容问题)
|
||||||
|
gzip_proxied any; # 对代理请求也启用压缩
|
||||||
|
|
||||||
|
# 隐藏nginx版本号(安全加固)
|
||||||
|
server_tokens off;
|
||||||
|
|
||||||
|
# 通用安全响应头(全局生效)
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN"; # 防止点击劫持
|
||||||
|
add_header X-XSS-Protection "1; mode=block"; # 防XSS攻击
|
||||||
|
add_header X-Content-Type-Options "nosniff"; # 防止MIME类型嗅探
|
||||||
|
|
||||||
|
# 反向代理配置 http://10.4.126.112:23000
|
||||||
|
upstream upstream_name{
|
||||||
|
server 172.20.0.2:8090;
|
||||||
|
keepalive 32; # 长连接池大小,减少连接建立开销
|
||||||
|
keepalive_timeout 60s;
|
||||||
|
keepalive_requests 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 虚拟主机配置
|
||||||
|
server {
|
||||||
|
listen 8080;
|
||||||
|
listen [::]:8080;
|
||||||
|
# 建议替换为实际域名(如example.com),避免用localhost
|
||||||
|
server_name 10.4.126.116;
|
||||||
|
|
||||||
|
# 网站根目录
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
# 默认索引文件
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# API接口代理配置(优化版)
|
||||||
|
location ^~/api/ {
|
||||||
|
# 代理目标地址
|
||||||
|
proxy_pass http://upstream_name/;
|
||||||
|
|
||||||
|
# 增强头信息转发
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
gzip off; # 禁用该接口的 gzip 压缩
|
||||||
|
proxy_set_header Accept-Encoding ""; # 清除传给后端的 Accept-Encoding 头
|
||||||
|
|
||||||
|
# 超时设置(API专用,可根据业务调整)
|
||||||
|
proxy_connect_timeout 300s;
|
||||||
|
proxy_send_timeout 300s;
|
||||||
|
proxy_read_timeout 300s;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# 主路径匹配
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html; # 适合SPA应用(如Vue/React)
|
||||||
|
# 缓存控制:动态内容不缓存
|
||||||
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
|
add_header Pragma "no-cache";
|
||||||
|
add_header Expires "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
# 静态资源缓存优化(比原配置更精细)
|
||||||
|
location ~* \.(gif|jpg|jpeg|png|ico|svg|js|css|json|txt)$ {
|
||||||
|
# 缓存1天(可根据资源更新频率调整,如图片可设30d)
|
||||||
|
expires 1d;
|
||||||
|
add_header Cache-Control "public, max-age=86400";
|
||||||
|
# 防盗链:只允许指定域名引用资源(替换为实际域名)
|
||||||
|
# valid_referers none blocked localhost example.com *.example.com;
|
||||||
|
# if ($invalid_referer) {
|
||||||
|
# return 403;
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
|
||||||
|
# 错误页面配置
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
# 显式指定root(避免继承外层可能的变更)
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 禁止访问隐藏文件(如.git .env等)
|
||||||
|
location ~ /\. {
|
||||||
|
deny all;
|
||||||
|
access_log off;
|
||||||
|
log_not_found off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
179
server.js
179
server.js
@ -1,179 +0,0 @@
|
|||||||
const http = require('http');
|
|
||||||
const httpServer = require('http-server');
|
|
||||||
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const { PassThrough } = require('stream');
|
|
||||||
|
|
||||||
const staticRoot = './html';
|
|
||||||
const log = (message) => {
|
|
||||||
const timestamp = new Date().toISOString();
|
|
||||||
console.log(`[${timestamp}] ${message}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const staticServer = httpServer.createServer({
|
|
||||||
root: staticRoot,
|
|
||||||
showDir: false,
|
|
||||||
cors: true,
|
|
||||||
autoIndex: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const proxyConfig = {
|
|
||||||
path: "/api",
|
|
||||||
target: "http://172.20.0.2:8090"
|
|
||||||
};
|
|
||||||
|
|
||||||
// 跟踪响应是否已处理
|
|
||||||
const responseHandled = new WeakMap();
|
|
||||||
|
|
||||||
const apiProxy = createProxyMiddleware({
|
|
||||||
target: proxyConfig.target,
|
|
||||||
changeOrigin: true,
|
|
||||||
pathRewrite: {'^/api': '' },
|
|
||||||
logLevel: 'silent',
|
|
||||||
timeout: 120000,
|
|
||||||
// 禁用内置的分块处理,手动控制
|
|
||||||
selfHandleResponse: true,
|
|
||||||
onTimeout: (req, res) => {
|
|
||||||
if (!responseHandled.has(res)) {
|
|
||||||
responseHandled.set(res, true);
|
|
||||||
res.writeHead(504, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({ error: 'Proxy timeout' }));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
on: {
|
|
||||||
proxyReq: (proxyReq, req, res) => {
|
|
||||||
const forwardedUrl = `${proxyReq.protocol}//${proxyReq.host}:${proxyReq.port}${proxyReq.path}`;
|
|
||||||
log(`转发请求到: ${proxyReq.method} ${forwardedUrl}`);
|
|
||||||
log(`请求头: ${JSON.stringify(req.headers, null, 2)}`);
|
|
||||||
|
|
||||||
const contentType = req.headers['content-type'] || '';
|
|
||||||
if (contentType.includes('application/json')) {
|
|
||||||
let requestBody = '';
|
|
||||||
req.on('data', (chunk) => { requestBody += chunk.toString(); });
|
|
||||||
req.on('end', () => { log(`请求体: ${requestBody}`); });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
proxyRes: (proxyRes, req, res) => {
|
|
||||||
if (responseHandled.has(res)) {
|
|
||||||
log(`已处理响应,跳过重复处理: ${req.url}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
responseHandled.set(res, false);
|
|
||||||
|
|
||||||
log(`后端响应: ${proxyRes.statusCode} (${req.url})`);
|
|
||||||
log(`响应头: ${JSON.stringify(proxyRes.headers, null, 2)}`);
|
|
||||||
|
|
||||||
const contentType = proxyRes.headers['content-type'] || '';
|
|
||||||
const isChunked = proxyRes.headers['transfer-encoding'] === 'chunked';
|
|
||||||
|
|
||||||
// 复制响应头(排除可能引起冲突的头)
|
|
||||||
if (!res.headersSent) {
|
|
||||||
res.statusCode = proxyRes.statusCode;
|
|
||||||
Object.keys(proxyRes.headers).forEach(key => {
|
|
||||||
// 排除分块传输和连接控制头,由Node.js自动处理
|
|
||||||
if (!['transfer-encoding', 'connection', 'content-length'].includes(key)) {
|
|
||||||
res.setHeader(key, proxyRes.headers[key]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理JSON响应
|
|
||||||
if (contentType.includes('application/json')) {
|
|
||||||
let responseBody = '';
|
|
||||||
const logStream = new PassThrough();
|
|
||||||
|
|
||||||
// 收集数据用于日志
|
|
||||||
logStream.on('data', (chunk) => {
|
|
||||||
responseBody += chunk.toString();
|
|
||||||
});
|
|
||||||
|
|
||||||
logStream.on('end', () => {
|
|
||||||
log(`响应体: ${responseBody}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 分块传输处理
|
|
||||||
if (isChunked) {
|
|
||||||
// 直接通过流转发,保留分块特性
|
|
||||||
proxyRes.pipe(logStream).pipe(res);
|
|
||||||
} else {
|
|
||||||
// 非分块传输,收集完再发送
|
|
||||||
proxyRes.on('data', (chunk) => {
|
|
||||||
responseBody += chunk.toString();
|
|
||||||
});
|
|
||||||
proxyRes.on('end', () => {
|
|
||||||
if (!responseHandled.get(res)) {
|
|
||||||
responseHandled.set(res, true);
|
|
||||||
log(`响应体: ${responseBody}`);
|
|
||||||
res.end(responseBody);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 非JSON响应直接转发
|
|
||||||
proxyRes.pipe(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听响应结束
|
|
||||||
proxyRes.on('end', () => {
|
|
||||||
responseHandled.set(res, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
proxyRes.on('error', (err) => {
|
|
||||||
if (!responseHandled.get(res)) {
|
|
||||||
responseHandled.set(res, true);
|
|
||||||
log(`响应错误: ${err.message}`);
|
|
||||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({ error: '响应处理错误' }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
error: (err, req, res) => {
|
|
||||||
if (!responseHandled.has(res) || !responseHandled.get(res)) {
|
|
||||||
responseHandled.set(res, true);
|
|
||||||
log(`代理错误 [${err.code}]: ${err.message} (请求: ${req.url})`);
|
|
||||||
if (!res.headersSent) {
|
|
||||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
||||||
}
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
error: '代理服务错误',
|
|
||||||
message: err.message
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
|
||||||
if (req.url.startsWith(proxyConfig.path)) {
|
|
||||||
log(`收到代理请求: ${req.method} ${req.url}`);
|
|
||||||
return apiProxy(req, res);
|
|
||||||
}
|
|
||||||
else if (req.url === '' || req.url === '/' || req.url.endsWith('/')) {
|
|
||||||
log(`访问根路径,返回index.html: ${req.url}`);
|
|
||||||
const indexPath = path.join(staticRoot, 'index.html');
|
|
||||||
|
|
||||||
if (fs.existsSync(indexPath)) {
|
|
||||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
||||||
fs.createReadStream(indexPath).pipe(res);
|
|
||||||
} else {
|
|
||||||
log(`警告: index.html不存在于 ${staticRoot}`);
|
|
||||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
||||||
res.end('index.html not found');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log(`处理静态文件请求: ${req.url}`);
|
|
||||||
staticServer.server.emit('request', req, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const port = 8080;
|
|
||||||
server.listen(port, () => {
|
|
||||||
log(`静态服务器已启动,监听端口 ${port}`);
|
|
||||||
log(`静态文件目录: ${path.resolve(staticRoot)}`);
|
|
||||||
log(`API代理目标: ${proxyConfig.target}`);
|
|
||||||
log(`访问地址: http://localhost:${port}`);
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user