hyb
2026-01-09 4cb426cb3ae31e772a09d4ade5b2f0242aaeefa0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
server {
    listen 8081;
    server_name localhost;  # 部署时替换成主机ip或域名
    client_max_body_size 100M;
 
    # 开启gzip
    gzip on;
    # https://blog.csdn.net/fxss5201/article/details/106535475
    gzip_static on;
    gzip_proxied any;
    # 低于1kb的资源不压缩
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    # 需要压缩的类型
    gzip_types text/plain application/javascript text/css application/xml text/javascript application/json;
    # 是否添加“Vary: Accept-Encoding”响应头
    gzip_vary on;
 
    location /django_static/ {
        alias /www/LunarLink/static/;
    }
 
    location /api/ {
        proxy_pass http://lunar-link-django:8000/api/;
        proxy_set_header Host $host;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect default;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    }
 
    location /admin/ {
        proxy_pass http://lunar-link-django:8000/admin/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
 
    location = / {
        rewrite ^ /lunarlink/login redirect;
    }
 
    location / {
        root /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }
}