初始化
This commit is contained in:
156
server/docs/nginx-production.conf
Normal file
156
server/docs/nginx-production.conf
Normal file
@@ -0,0 +1,156 @@
|
||||
# =============================================
|
||||
# 文件管理系统 - 生产环境 Nginx 配置
|
||||
# =============================================
|
||||
# 功能:
|
||||
# 1. 前端静态资源服务
|
||||
# 2. API反向代理到Go后端
|
||||
# 3. MinIO反向代理(预签名模式)
|
||||
# 4. X-Sendfile支持(中转模式优化)
|
||||
# 5. HTTPS配置(可选)
|
||||
# =============================================
|
||||
|
||||
worker_processes auto;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile off; # Windows环境建议关闭
|
||||
charset utf-8;
|
||||
|
||||
# 日志格式
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent"';
|
||||
|
||||
# Gzip压缩
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml;
|
||||
|
||||
# =============================================
|
||||
# Upstream
|
||||
# =============================================
|
||||
upstream fileserver {
|
||||
server 127.0.0.1:8080; # Go文件管理服务
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
upstream minio {
|
||||
server 127.0.0.1:9000; # MinIO服务(不暴露公网)
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# HTTP → HTTPS 重定向(可选)
|
||||
# =============================================
|
||||
# server {
|
||||
# listen 80;
|
||||
# server_name files.example.com;
|
||||
# return 301 https://$host$request_uri;
|
||||
# }
|
||||
|
||||
# =============================================
|
||||
# 主站配置
|
||||
# =============================================
|
||||
server {
|
||||
listen 80; # 或 443 ssl
|
||||
server_name files.example.com; # 替换为你的域名
|
||||
|
||||
client_max_body_size 500m; # 最大上传500MB
|
||||
|
||||
# SSL配置(可选)
|
||||
# ssl_certificate /path/to/cert.pem;
|
||||
# ssl_certificate_key /path/to/key.pem;
|
||||
# ssl_protocols TLSv1.2 TLSv1.3;
|
||||
|
||||
# access_log logs/access.log main;
|
||||
|
||||
# =============================================
|
||||
# 1. API请求 → Go后端
|
||||
# =============================================
|
||||
location ^~ /api/ {
|
||||
proxy_pass http://fileserver;
|
||||
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;
|
||||
|
||||
# 超时设置
|
||||
proxy_connect_timeout 30s;
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 2. MinIO反向代理(预签名模式)
|
||||
# 用户通过此路径直连MinIO获取文件
|
||||
# 关键: 必须保留签名参数
|
||||
# =============================================
|
||||
location ^~ /minio/ {
|
||||
proxy_pass http://minio/;
|
||||
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;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
|
||||
# 大文件下载超时
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
|
||||
# 禁用缓冲(流式传输)
|
||||
proxy_buffering off;
|
||||
|
||||
# 隐藏MinIO内部头
|
||||
proxy_hide_header X-Amz-Id-2;
|
||||
proxy_hide_header X-Amz-Request-Id;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 3. X-Sendfile路径(中转模式优化)
|
||||
# Go后端返回X-Accel-Redirect头时,
|
||||
# Nginx直接从本地路径发送文件
|
||||
# =============================================
|
||||
location ^~ /minio-files/ {
|
||||
internal; # 仅允许内部重定向, 外部不可直接访问
|
||||
|
||||
alias D:/Seeyon/A8/localfile/;
|
||||
|
||||
# 优化大文件传输
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
|
||||
# 缓存控制
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 4. 前端静态资源
|
||||
# =============================================
|
||||
location / {
|
||||
root D:/Seeyon/A8/frontend/dist; # 前端构建产物目录
|
||||
index index.html;
|
||||
|
||||
# SPA路由支持
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# 静态资源缓存
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 5. 安全头
|
||||
# =============================================
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
}
|
||||
}
|
||||
123
server/docs/nginx.conf
Normal file
123
server/docs/nginx.conf
Normal file
@@ -0,0 +1,123 @@
|
||||
# =============================================
|
||||
# 文件管理系统 Nginx 配置模板
|
||||
# 支持两种文件访问模式:
|
||||
# 1. 中转模式(proxy): Nginx → Server鉴权 → 返回文件
|
||||
# 2. 预签名模式(presigned): 客户端 → Nginx → MinIO
|
||||
# =============================================
|
||||
|
||||
worker_processes 1;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
sendfile off;
|
||||
charset utf-8;
|
||||
|
||||
# =============================================
|
||||
# Upstream: 后端服务 + MinIO
|
||||
# =============================================
|
||||
upstream fileserver {
|
||||
server 127.0.0.1:8080; # Go文件管理服务
|
||||
}
|
||||
|
||||
upstream minio {
|
||||
server 127.0.0.1:9000; # MinIO服务
|
||||
}
|
||||
|
||||
upstream minio_console {
|
||||
server 127.0.0.1:9001; # MinIO控制台
|
||||
}
|
||||
|
||||
server {
|
||||
listen 3090;
|
||||
server_name localhost;
|
||||
client_max_body_size 500m; # 最大上传500MB
|
||||
|
||||
# =============================================
|
||||
# 1. API请求 → 后端服务
|
||||
# =============================================
|
||||
location ^~ /api/ {
|
||||
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_pass http://fileserver;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 2. 静态文件 - 中转模式(X-Sendfile)
|
||||
# Server鉴权成功后返回X-Accel-Redirect头,
|
||||
# Nginx直接从本地路径发送文件, 不经过Server
|
||||
# =============================================
|
||||
location ^~ /minio-files/ {
|
||||
internal; # 仅允许内部重定向
|
||||
|
||||
# MinIO数据目录(或挂载点)
|
||||
alias D:/Seeyon/A8/localfile/;
|
||||
|
||||
# 优化大文件传输
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
|
||||
# 缓存控制
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 3. 预签名直连模式
|
||||
# 客户端拿到预签名URL后直接访问此路径
|
||||
# Nginx转发到MinIO, 保留原始签名参数
|
||||
# =============================================
|
||||
location ^~ /minio/ {
|
||||
# 反向代理到MinIO
|
||||
# 关键: 必须保留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;
|
||||
|
||||
# MinIO需要这些头来验证预签名
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
|
||||
# 超时设置(大文件下载)
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
|
||||
# 隐藏MinIO内部地址
|
||||
proxy_hide_header X-Amz-Id-2;
|
||||
proxy_hide_header X-Amz-Request-Id;
|
||||
|
||||
proxy_pass http://minio;
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 4. MinIO控制台(管理用, 可选)
|
||||
# =============================================
|
||||
location ^~ /minio-console/ {
|
||||
proxy_pass http://minio_console/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# WebSocket支持(MinIO控制台需要)
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
# =============================================
|
||||
# 5. 前端静态资源
|
||||
# =============================================
|
||||
location / {
|
||||
root D:/Seeyon/A8/frontend/dist;
|
||||
index index.html;
|
||||
|
||||
# SPA路由支持
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user