From 686d1e718455acdba56dbbd9cd2d3c174b72f3ad Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Fri, 27 Feb 2026 10:26:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(nginx):=20=E9=87=8D=E6=9E=84nginx?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重新组织location块并添加清晰的分区注释 - 新增多个API接口的代理配置 - 修正client_max_body_size的注释说明 - 保持原有功能不变的情况下提高配置可读性 --- nginx.conf | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/nginx.conf b/nginx.conf index 367ccfe..5c91b9f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -5,11 +5,15 @@ events { http { include /etc/nginx/mime.types; default_type application/octet-stream; - client_max_body_size 10G; # 允许的最大文件大小为 20MB + client_max_body_size 10G; # 允许的最大文件大小为 10GB server { listen 3001; server_name localhost; + + # ============================================ + # 用户认证相关接口 (/user-api/*) + # ============================================ location /user-api/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -20,6 +24,10 @@ http { proxy_set_header Authorization $http_authorization; proxy_pass http://localhost:33333/user/; } + + # ============================================ + # 文件服务接口 (/file/*) + # ============================================ location /file/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -29,8 +37,12 @@ http { proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Authorization $http_authorization; proxy_pass http://localhost:33333/file/; - } - location /api/story/ { + } + + # ============================================ + # Story 相关接口 (/api/story/*) + # ============================================ + location /api/story/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; @@ -38,11 +50,72 @@ http { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Authorization $http_authorization; - proxy_pass http://localhost:33333/api/story/; - } + proxy_pass http://localhost:33333/story/; + } + # ============================================ + # 用户服务接口 (/api/user/*) + # 包含: 用户资料、偏好设置、相册、集合等 + # ============================================ + location /api/user/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header Authorization $http_authorization; + proxy_pass http://localhost:33333/user/; + } + + # ============================================ + # API v1 版本接口 (/api/v1/*) + # 包含: 评论、点赞、同步、统计等 + # ============================================ + location /api/v1/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header Authorization $http_authorization; + proxy_pass http://localhost:33333/user/api/v1/; + } + + # ============================================ + # 地理信息接口 (/api/geographic/*) + # ============================================ + location /api/geographic/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header Authorization $http_authorization; + proxy_pass http://localhost:33333/api/geographic/; + } + + # ============================================ + # 通用 API 接口 (/api/*) + # 用于其他未明确配置的 API 路径 + # ============================================ + location /api/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header Authorization $http_authorization; + proxy_pass http://localhost:33333/api/; + } + + # ============================================ # MinIO 对象存储代理 # 需要在后端配置 minio.externalEndpoint 为 http:///minio + # ============================================ location /minio/ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -51,6 +124,9 @@ http { proxy_pass http://localhost:9000/; } + # ============================================ + # 前端静态资源 + # ============================================ location / { root /usr/share/nginx/html; index index.html index.htm;