jiachenlong/config_src/nginx.conf

61 lines
1.7 KiB
Nginx Configuration File
Raw Normal View History

# Nginx 配置 - 甲辰藏品管理系统 v1.0.0
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.html;
# 允许上传最大 20MB 的文件
client_max_body_size 20M;
# 前端静态文件SPA 路由)
location / {
try_files $uri $uri/ /index.html;
}
# 静态资源目录(图片、图标、字体)
location /static {
alias /var/www/html/static;
expires 30d;
add_header Cache-Control "public, immutable";
}
# API 代理到后端
location /api {
proxy_pass http://47.110.37.129:3000/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_set_header X-Forwarded-Proto $scheme;
client_max_body_size 20M;
}
# 缓存静态资源(必须在 /uploads 之前,否则图片会被代理)
location ~* \.(js|css|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# 图片上传文件代理(必须在图片扩展名 location 之前)
location /uploads {
proxy_pass http://47.110.37.129:3000/uploads;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20M;
}
# 前端静态图片缓存
location ~* ^/static/.*\.(png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
}
}