优化更新
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
# DjangoAdmin Nginx 反向代理配置
|
||||
# 部署时修改 server_name、root、proxy_pass 为实际值
|
||||
|
||||
upstream fastapi_backend {
|
||||
server 127.0.0.1:8031;
|
||||
keepalive 16;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name your-domain.com;
|
||||
|
||||
charset utf-8;
|
||||
client_max_body_size 50m;
|
||||
|
||||
# 安全头
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
|
||||
# Gzip
|
||||
gzip on;
|
||||
gzip_min_length 1k;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml image/svg+xml;
|
||||
gzip_vary on;
|
||||
|
||||
# 前端静态资源
|
||||
root /data/apps/djangoadmin/frontend/dist;
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /assets/ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# API 反向代理
|
||||
location /api/ {
|
||||
proxy_pass http://fastapi_backend/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
# 透传上游X-Forwarded-For(不追加本机IP);无上游头时回退到直连IP
|
||||
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Connection "";
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_read_timeout 120s;
|
||||
proxy_send_timeout 60s;
|
||||
}
|
||||
|
||||
# 上传文件访问
|
||||
location /api/file/ {
|
||||
alias /data/apps/djangoadmin/uploads/;
|
||||
expires 7d;
|
||||
access_log off;
|
||||
limit_except GET { deny all; }
|
||||
}
|
||||
|
||||
# 禁止访问隐藏文件
|
||||
location ~ /\. { deny all; }
|
||||
}
|
||||
Reference in New Issue
Block a user