You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.6 KiB
105 lines
3.6 KiB
worker_processes auto;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# 对齐 application.yml 的 spring.servlet.multipart.max-request-size(25M)
|
|
client_max_body_size 25M;
|
|
|
|
sendfile on;
|
|
keepalive_timeout 65;
|
|
gzip on;
|
|
gzip_types text/css application/javascript application/json image/svg+xml;
|
|
|
|
upstream crm_app {
|
|
server crm-app:8080;
|
|
}
|
|
|
|
# 缩略图代理缓存区(10MB 内存索引,100MB 磁盘,1天不访问则淘汰)
|
|
proxy_cache_path /var/cache/nginx/thumbnails
|
|
levels=1:2
|
|
keys_zone=thumb_cache:10m
|
|
max_size=100m
|
|
inactive=1d
|
|
use_temp_path=off;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
# ========== 静态文档页(浏览器缓存 1 天) ==========
|
|
location /crm-api/docs/ {
|
|
alias /usr/share/nginx/docs/;
|
|
index crm-api-docs-documentation.html;
|
|
expires 1d;
|
|
add_header Cache-Control "public, max-age=86400";
|
|
}
|
|
location = /crm-api/docs {
|
|
return 301 /crm-api/docs/;
|
|
}
|
|
location /docs/ {
|
|
alias /usr/share/nginx/docs/;
|
|
index crm-api-docs-documentation.html;
|
|
expires 1d;
|
|
add_header Cache-Control "public, max-age=86400";
|
|
}
|
|
location = /docs {
|
|
return 301 /docs/;
|
|
}
|
|
|
|
# ========== 缩略图(nginx 代理缓存) ==========
|
|
# 后端对 READY 缩略图返回 Cache-Control: max-age=86400 → nginx 缓存
|
|
# 后端对占位图返回 Cache-Control: no-cache → nginx 不缓存(尊重后端)
|
|
# 带 /crm-api 前缀
|
|
location /crm-api/api/file/thumbnail {
|
|
proxy_pass http://crm_app/api/file/thumbnail;
|
|
proxy_cache thumb_cache;
|
|
proxy_cache_key "$scheme$request_method$host$request_uri";
|
|
proxy_cache_valid 200 1d;
|
|
proxy_cache_valid 404 1m;
|
|
proxy_cache_use_stale error timeout updating;
|
|
add_header X-Cache-Status $upstream_cache_status;
|
|
proxy_set_header Host $host;
|
|
}
|
|
# 不带前缀
|
|
location /api/file/thumbnail {
|
|
proxy_pass http://crm_app;
|
|
proxy_cache thumb_cache;
|
|
proxy_cache_key "$scheme$request_method$host$request_uri";
|
|
proxy_cache_valid 200 1d;
|
|
proxy_cache_valid 404 1m;
|
|
proxy_cache_use_stale error timeout updating;
|
|
add_header X-Cache-Status $upstream_cache_status;
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
# ========== 带 /crm-api 前缀的 API(去掉前缀转发) ==========
|
|
location /crm-api/ {
|
|
proxy_pass http://crm_app/;
|
|
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_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
proxy_request_buffering off;
|
|
}
|
|
|
|
# ========== 不带前缀直接转发 ==========
|
|
location / {
|
|
proxy_pass http://crm_app;
|
|
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_read_timeout 300s;
|
|
proxy_send_timeout 300s;
|
|
proxy_request_buffering off;
|
|
}
|
|
}
|
|
}
|
|
|